Solved

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

Posted on 2002-05-14
13
1,088 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
  • 4
  • 4
  • 3
  • +2
13 Comments
 
LVL 7

Expert Comment

by:Motaz
Comment Utility
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
Comment Utility
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
Comment Utility
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
 
LVL 6

Expert Comment

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

Author Comment

by:aztec
Comment Utility
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
Comment Utility
>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
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
LVL 6

Accepted Solution

by:
DrDelphi earned 50 total points
Comment Utility
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
Comment Utility
ooops... forgot to mention that you'll have to includse ShellApi in your uses. Carry on....


0
 
LVL 17

Expert Comment

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

Author Comment

by:aztec
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Thanks - works great DrDelphi! Tell me - could this function also be used to 'nuke' a specific filename?

Thanks
   Shawn
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

772 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now