Solved

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

Posted on 2002-05-14
13
1,095 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

726 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