Solved

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

Posted on 2002-05-14
13
1,096 Views
Last Modified: 2008-02-26
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
Comment
Question by:aztec
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
  • 3
  • +2
13 Comments
 
LVL 7

Expert Comment

by:Motaz
ID: 7009241
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
 

Author Comment

by:aztec
ID: 7009251
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
 
LVL 7

Expert Comment

by:Motaz
ID: 7009279
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!

 
LVL 6

Expert Comment

by:DrDelphi
ID: 7009281
I have seen this happen when Explorer itself has a folder open.
0
 

Author Comment

by:aztec
ID: 7009340
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
 
LVL 7

Expert Comment

by:Motaz
ID: 7009368
>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
 
LVL 6

Accepted Solution

by:
DrDelphi earned 50 total points
ID: 7009390
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
 
LVL 6

Expert Comment

by:DrDelphi
ID: 7009391
ooops... forgot to mention that you'll have to includse ShellApi in your uses. Carry on....


0
 
LVL 17

Expert Comment

by:inthe
ID: 7009782
rmdir could also fail if you have any subfolders under the thisdir folder.
0
 

Author Comment

by:aztec
ID: 7009882
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
 
LVL 3

Expert Comment

by:raidos
ID: 7010480
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
 
LVL 6

Expert Comment

by:DrDelphi
ID: 7011139
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
 

Author Comment

by:aztec
ID: 7047526
Thanks - works great DrDelphi! Tell me - could this function also be used to 'nuke' a specific filename?

Thanks
   Shawn
0

Featured Post

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!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

689 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question