deleteFile does not work

Hi to everybody,

I am trying to clean up a folder contents before generating some new files into. I wanted to use simple deleteFile command to do this and tried following code (which is same as in examples)

string dir = "d:\\tmp\\doorsCodeGen" 
string file 
string errMsg
for file in directory dir do {
   print file " -> "
   errMsg = deleteFile(file)
   print errMsg "\n"
}

 


and output...

 

 

. -> delete file failed
.
.. -> delete file failed
..
Footer.cs -> 
Header.cs -> 
Messages1.cs ->



Then I saw that "." and ".." are seen in file content of this folder which leads me to



 

 

 

string dir = "d:\\tmp\\doorsCodeGen" 
string file 
string errMsg
for file in directory dir do {
   if(file != "." && file != "..") {
      print file " -> "
      errMsg = deleteFile(file)
      print errMsg "\n"
   }
}



and outputs..



 

 

 

Footer.cs -> 
Header.cs -> 
Messages1.cs ->


I am on Win XP 32 bit and this drive is NTFS. Unfortunately, this code does not delete files without any sign of error. Is there any idea, why does not it work?

Thank you in advance
Celal
Email: ckucukoguz@tai.com.tr
TAI

 


celalbaba - Tue Dec 27 02:00:20 EST 2011

Re: deleteFile does not work
celalbaba - Tue Dec 27 02:16:09 EST 2011

After more forum research :) I found system commands are useful:
 

string path = "d:\\tmp\\doorsCodeGen\\*.*"
string commandexe = "c:\\windows\\system32\\cmd.exe /c del /Q /F" path ""
system (commandexe)

 


this code does what I want in a different way. But, my question is still not answered, why deleteFile does not work?
Thank you in advance
Celal
Email: ckucukoguz@tai.com.tr
TAI

 

Re: deleteFile does not work
celalbaba - Tue Dec 27 02:29:58 EST 2011

celalbaba - Tue Dec 27 02:16:09 EST 2011

After more forum research :) I found system commands are useful:
 

string path = "d:\\tmp\\doorsCodeGen\\*.*"
string commandexe = "c:\\windows\\system32\\cmd.exe /c del /Q /F" path ""
system (commandexe)

 


this code does what I want in a different way. But, my question is still not answered, why deleteFile does not work?
Thank you in advance
Celal
Email: ckucukoguz@tai.com.tr
TAI

 

and there will be a space after /F to separate arguments and path

Re: deleteFile does not work
a_vestlin - Tue Dec 27 03:30:40 EST 2011

Hi

You should probably add the path to the file.

/Anders

Re: deleteFile does not work
celalbaba - Tue Dec 27 03:35:17 EST 2011

a_vestlin - Tue Dec 27 03:30:40 EST 2011
Hi

You should probably add the path to the file.

/Anders

Thank you Anders, this worked:
 

string dir = "d:\\tmp\\doorsCodeGen" 
string file 
string errMsg
for file in directory dir do {
   if(file != "." && file != "..") {
      print file " -> "
      errMsg = deleteFile(dir "\\" file)
      print errMsg "\n"
   }
}