Quantcast
Channel: Active questions tagged windows - Super User
Viewing all articles
Browse latest Browse all 9683

File Writing in C:\ drive

$
0
0

So, I understand that files cannot be created or deleted without administrator privileges in the C:\ drive. My question is like this : If a directory in the C:\ drive is entered... say Program Files, then shouldn't file writing be possible there?

I have created a program that deletes empty directories in an entire folder (i.e includes subfolders)

I get that C:\ drive requires permissions, but once my program finds Program Files to be a "not-empty" directory, it enters Program Files but is still denied write permissions. I know this because I made sure the program lists every directory it spots in the given path. So, EVERY folder present in the C:\ drive is printed. No folders are deleted though.

Whereas when I set the path directly to C:\Program Files it performs the task of deleting empty directories as per the code.

Why is this so?

I wrote a batch file which I ran as the administrator. As you might have guessed, no luck. I tried running it through cmd in admin mode, but nothing again. Is there a way I can change the .class file of my code to run with admin privileges? Or is there a way to run it in cmd with admin privileges? Say

java emptyFoldersRemover -runAsAdmin

Something like that?

Or do I have to make an executable file?

EDIT

I stress on this point again. Isn't there a way to run java.exe with administrator permissions in cmd so that the program is treated with administrator privileges?

String absolutePath=p;try {    path=new File(absolutePath);    File listOfFolders[] = path.listFiles();    for(int i=0;i<listOfFolders.length;i++)    if(listOfFolders[i].isDirectory())        System.out.println(listOfFolders[i]);    for (int i = 0; i < listOfFolders.length; i++)     {        if (listOfFolders[i].isDirectory())         {            if(listOfFolders[i].list().length>0) {                /* if(listOfFolders[i].getName().equalsIgnoreCase("Program Files"))                {                   for(int j=0;j<listOfFolders[i].list().length;j++)                   {                       System.out.println(listOfFolders[i].list());                   }                }*/                run(listOfFolders[i].getAbsolutePath());            }            else            {                noOfFolders++;                System.out.println(noOfFolders);                listOfFolders[i].delete();            }        }    }}catch(Exception e){    //e.printStackTrace();}return(noOfFolders);

Viewing all articles
Browse latest Browse all 9683