Windows 7 blocking java.io.File methods? -
here's program takes pdf files in given folder, adds date prefix , filters out umlauts. worked on win xp install not on fresh win7 one, exact same code terminates because of nullpointerexception in replacesymbolsindir(string)
's line 4, that's empty line right before for-loop.
i triggered process compiling in eclipse:
import java.io.file; public class loadfile { public static string dir = "c:\\users\\username\\desktop\\pdfdirectory\\"; public static string date = "130406"; public static void main(string args[]) { replacesymbolsindir(dir); addprefix(dir, date + "-"); } public static void replacesymbolsindir(string path){ file folder = new file(path); file[] filearray = folder.listfiles(); for(int = 0; i<filearray.length; i++) { file currentfile = filearray[i]; if(currentfile.getname().tolowercase().endswith(".pdf")) { currentfile.renameto(new file(path, replacesymbolsinstring(currentfile.getname()))); } } } public static string replacesymbolsinstring(string s) { //figure out regex string result = s.replace('ä','a'); result = result.replace('ö','o'); result = result.replace('ü','u'); result = result.replace('ß','s'); result = result.replace(' ','-'); return result; } public static void addprefix(string path, string prefix) { file folder = new file(path); file filearray[] = folder.listfiles(); for(int = 0; i<filearray.length; i++) { file currentfile = filearray[i]; if(!currentfile.getname().startswith(prefix) && currentfile.getname().tolowercase().endswith(".pdf")) { string newname = prefix + "" + currentfile.getname(); currentfile.renameto(new file(path, newname)); } } } }
is win7 blocking methods try find information files , folders? seems like
folder.listfiles();
is coming null , that's issue.
any ideas besides path being wrong? because that's ctrl+c/v out of explorer window plus escapes , should therefore correct.
edit: i'm running program on existing user account, account management window labels "admin". running cmd after opening cmd admin produces npe.
edit2: said, folder defaults being write protected , can't changed, that's seems root cause. i'll it...
windows 7 doesn't allow 1 user read files or folders in user's directory default, whereas windows xp does. you'll need 1 of 2 things:
- get user folder grant 'read' permission user running code, or
- run code elevated permissions (e.g. elevated command prompt) using uac.
Comments
Post a Comment