Solved

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

Posted on 2002-05-14
13
1,092 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
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
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 
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

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Delphi cmd execution 6 62
Delphi Dbf export problem to a Visual Foxpro application 6 190
Can Viruses spread while transferring Binary data with Winsock 2 77
Delphi 2 60
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
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…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

822 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