0

I cant empty my recycle bin using c program it gives a "file path not specified" error. It works perfectly when i past the command in the command prompt but not in the c program. Even tried running visual studio in administrator mode.

int BinFiles()
{   
char folderCommand[]= "rd /s %systemdrive%\$Recycle.bin";
system(folderCommand);
return 0;
}
Community
  • 1
  • 1
Zimad
  • 343
  • 1
  • 5
  • 13
  • 1
    Did you try to replace the environment variable with the value in the string you pass to `system`? – harper Feb 04 '15 at 10:14
  • 3
    Try using // instead of / and \\ instead of \. – Spikatrix Feb 04 '15 at 10:19
  • possible duplicate of [Why do I have to use double backslashes for file-paths in code?](http://stackoverflow.com/questions/28328052/why-do-i-have-to-use-double-backslashes-for-file-paths-in-code) – sashoalm Feb 04 '15 at 18:04

2 Answers2

0

You need to escape the \ character:

int BinFiles()
{   
    char folderCommand[]= "rd /s %systemdrive%\\$Recycle.bin";
    system(folderCommand);
    return 0;
}
Klas Lindbäck
  • 33,105
  • 5
  • 57
  • 82
  • There should be a question like "why are files specified with a single backslash in code not being found" so we can mark all such questions as duplicates to it. – sashoalm Feb 04 '15 at 11:11
  • @sashoalm There probably is, although I couldn't find one. I guess that questions on this don't have the appropriate keywords in the title. If you can't find one you can always change the title of this question. – Klas Lindbäck Feb 04 '15 at 11:34
0
rd /s c:\$Recycle.Bin

(In the above command, “c” is your Windows drive)

Then Press Y key

C:\WINDOWS\system32>rd /s c:\#Recycle.Bin
c:\#Recycle.Bin, Are you sure (Y/N)? Y
Amranur Rahman
  • 1,061
  • 17
  • 29