• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1100
  • Last Modified:

I/O 32 error in Win 2000, but not in Win 98

Hi...
  My application checks to see if a directory exists, if it does, it deletes all files in that directory, then removes the directory. This works great in Win 98, but generates an I/O 32 error in Win 2000... very strange. I know I/O 32 means that the file you're trying to use is being hit on by another program, but this is not the case here, as far as I can tell.

Any idea what's going on?

My code looks like this:

tempslist:=GetAllFileNames(thisdir);
for x:=0 to (tempslist.count - 1) do
begin
  if tempslist[x][1] <> '.' then
     sysutils.deletefile(thisdir+tempslist[z]);
end;
RmDir(thisdir);


'GetAllFilenames' is a function I wrote to return a TStringList with all the file names in a given directory... it's always worked fine. I'm using Delphi 3 Pro.

Maybe I'm going about this in a long-winded way... is there some super-quick way to programmatically delete a directory and its contents that I don't know about?


Thanks
   Shawn
0
aztec
Asked:
aztec
  • 4
  • 4
  • 3
  • +2
1 Solution
 
MotazCommented:
Please check the list and make sure that '.' and '..' not included in files, moreover chech that there is no readonly or hidden file.

Motaz
0
 
aztecAuthor Commented:
I do check for '.' and '..' - that's what this line does:

if tempslist[x][1] <> '.' then


And the files are not read-only or hidden. They are normal 'archive'.
0
 
MotazCommented:
yes, I saw.
did you know which file exactly cann't be deleted or make this problem, may be there is a wrong name for file name.

Also make sure that you are not currently working in this directory (Not a current directory)
Also make sure that there is no application set this directory as a working directory at the time of deletion.

Motaz
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
DrDelphiCommented:
I have seen this happen when Explorer itself has a folder open.
0
 
aztecAuthor Commented:
I don't know exactly which file the error comes up on... I do not have win2000 here, only win 98 and it works fine for me here. It is one of my users who has Win2000 and is having this problem. Actually 3 separate users having the same problem.

>Also make sure that you are not currently working in this >directory (Not a current directory)

You mean via my program, or viw Windows Explorer?


>Also make sure that there is no application set this >directory as a working directory at the time of
>deletion.

No other applications are open.

It is very strange, the same circumstances that work fine in Win 98, fail in Win 2000.


>I have seen this happen when Explorer itself has a folder open.

You mean when any folder in Windows Explorer is open? And this peculiar to only Win 2000.
So I should try closing out Windows Explorer and try it again?

Thanks
   Shawn

P.S: Is the method I use the best way to delete a directory that contains files? Maybe an alternative method might solve everything.
0
 
MotazCommented:
>Also make sure that you are not currently working in this >directory (Not a current directory)

>You mean via my program, or viw Windows Explorer?

I mean your program.

Also you can the file that produces the error, for example:


tempslist:=GetAllFileNames(thisdir);
for x:=0 to (tempslist.count - 1) do
begin
 if tempslist[x][1] <> '.' then
    if not sysutils.deletefile(thisdir+tempslist[z]) then
      ShowMessage('Unable to delete ' + ThisDir + TempsList[z]);
end;
RmDir(thisdir);

Also make sure that ThisDir + TempsList... will not result in bad path name such as:
  d:\DirecotyFile1.txt
or
  d:\\File1.txt

If you can know which files exactly that produces this error you can see it's Attribute and verfity it's naming.

I don't know another alternative to Delete directory

Motaz
0
 
DrDelphiCommented:
use this instead:


function NukeFolder(dir: string): Boolean;
var
  fileOp: TSHFileOpStruct;
begin
  ZeroMemory(@FileOp, SizeOf(Fileop));
  with fileOp do
  begin
    wFunc  := FO_DELETE;
    fFlags := FOF_SILENT or FOF_NOCONFIRMATION;
    pFrom  := PChar(dir + #0);
  end;
  Result := (0 = ShFileOperation(fileop));
end;



Good luck!!

0
 
DrDelphiCommented:
ooops... forgot to mention that you'll have to includse ShellApi in your uses. Carry on....


0
 
intheCommented:
rmdir could also fail if you have any subfolders under the thisdir folder.
0
 
aztecAuthor Commented:
Hi DrDelphi - your 'NukeFolder' seems to work well - but I've yet to try it on a win2000 machine (only my win 98). But I'm getting the feeling that the main thing causing the error was the manner in which I was retrieving all the file names from a directory. I'm thinking that worked fine in 98, but somehow 2000 didn't like it. The routine I was using to do that, was suggested to me in a separate question by you actually! Here it is:

Function GetAllfileNames(dir:string):Tstrings;
var list:TstringList;
   srch:TSearchRec;
begin
   if FindFirst(dir+'\*.*',faanyfile,srch)=0 then
   begin
    List:=TStringList.create;
    List.Add(srch.Name);
   end;
   While FindNext(srch)=0 do
   begin
      List.add(srch.name);
   end;
  result:=List;
end;

I'm thinking it might be getting crossed up on the default directory entries '..' and '.' under win2000/XP.

I say this because I use the GetALLFilenames function in another routine of mine which is also strangely failing/acting strange in Win 2000/XP but working fine in 98. Any thoughts on this or maybe a more robust workaround to the "GetAllFileNames" solution?

Thanks
   Shawn

0
 
raidosCommented:
You are missing a call to FindClose(srch) at the end of your function, that will likely make the function hold the Directory open in some handle resulting in the inability to be deleted...perhaps..

Regards
//raidos
0
 
DrDelphiCommented:
that's a real possibility. I neglected to put the FindClose in my original posting... Sorry. Now, as for the deletion of the directory, the routine that I gave yesterday (NukeFolder) is tested in NT,2000 and 98SE with no troubles. So, I guess the issue is if you want to use NukeFolder versus debugging the iteration through all the files in the directory. Your call...



Good luck!!
0
 
aztecAuthor Commented:
Thanks - works great DrDelphi! Tell me - could this function also be used to 'nuke' a specific filename?

Thanks
   Shawn
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 4
  • 4
  • 3
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now