Sign in to follow this  
Followers 0
OregonJohn

DirRemove not quite working for me

3 posts in this topic

I've spent probably 20 hours over the last week trying to solve this riddle. Perhaps there is no solution and it is just a limit of the beast we are working with. Any help you can provide would be greatly appreciated.

My primary goal is to process a group of client folders. Each client folder is full of sub-directories with tif files that I will turn into OCRed PDFs. As they are completed the files are moved into a new folder maintaining the original client folder structure. From the new directory they will be checked for quality. New client folders get added to be processed on a regular basis, though at some times there will be no clients to be processed. The final script needs to process what is already in the directory and wait if it is empty until new client folders arrive. I'm successfully using "While 1 = 1" to do that last part.

Moving the files and getting the directory structure is not a problem.

Once a sub-directory is empty I want to delete that sub-directory before moving on to the next. And, once a client folder is completed I want to delete that client folder before moving on to the next client. Herein lies the problem.

Though the script says to remove a directory (if there are no files or sub-directories in it) the directories are not getting deleted at the time told. To further complicate matters, the 2nd level sub-directories never get deleted unless I delete them all at once. Funny thing is that I can pause the script and then delete the sub-directories or individual client folder directly or with a separate script (I tested that last just to be sure it wasn't AutoIt3).

I know that some folders may not be in a state where they are able to be deleted, but as I said I could delete them when the script was paused so I'm not sure what is happening to prevent the script from deleting them when told to do so.

At the moment I am thinking that a folder that is somehow currently in the scripted loop has particular qualities that it does not have when the script is paused. Since I don't know anything behind AutoIt3, or the particulars of how FileFindFirstFile works, I'm at a complete loss to explain the behavior.

I created a test script that doesn't involve the OCRing and just moves files and directories to a new directory. The problem persists into the new script.

I am using a loop involving FileFindFirstFile. I am pasting the relevant portion of the script here and uploading the full script. This is the portion that doesn't want to delete the directory when told to and that doesn't delete the actual 2nd level folders (though it does manage to delete 3rd and 4th level folders several steps after being told to do so). I thought a brief section might suffice for analysis.

======================

Standard FileFindFirstFile with While loop

======================

Else

FileMove($FullFilePath,"c:\loop3\" & StringTrimLeft($SourceFolder,3) & "\",9)

$aSize = DirGetSize($SourceFolder)

If $aSize = 0 Then

DirRemove($SourceFolder,1)

ExitLoop

EndIf

EndIf

======================

I've been looking at that code for so long that it makes sense to me. If you want to see the whole script just let me know. The whole script includes a GUI so I can keep track of what's getting moved and when. The GUI has helped me understand a lot.

New recursive_original_1.au3

Share this post


Link to post
Share on other sites



Looking at their size of the description you gave of the problem is showing that you are having problems isolating the issue. There are good standard methods for isolating problems, but since you've come for help I can't let you go empty handed.

Here are some pointers:

- Before you do a DirRemove, check the value of $SourceFolder.

- Check if the directory can actually be removed. Try this manually and make sure no security errors occur.

- Check the return value of DirRemove and the value of @error and @extended after the function call. Print these to console!

- Add many short ConsoleWrite messages so you know what your app is doing. I usually do something like this:

_d("Setting vars")
; set some variables

_d("Starting main loop")
while 1
   _d("Iteration main loop")
   ; some functions
wend

; some functiosn, again with _d inside.

Func _d($s)
  ConsoleWrite($s & @CRLF)
EndFunc

And lastly:

- Sleep over it. This is a tried and proven method for solving problems, so use it!

I wish you the best of luck. Please don't hesitate to ask any other questions you have.

Share this post


Link to post
Share on other sites

Thanks, already got me thinking how to further test for my problem. And thanks for the consolewrite function. I had heard about that but didn't know how to use it...I was using a bunch of msgbox windows but they were so tedious. I'll update this topic as I make progress.

Looking at their size of the description you gave of the problem is showing that you are having problems isolating the issue. There are good standard methods for isolating problems, but since you've come for help I can't let you go empty handed.

Here are some pointers:

- Before you do a DirRemove, check the value of $SourceFolder.

- Check if the directory can actually be removed. Try this manually and make sure no security errors occur.

- Check the return value of DirRemove and the value of @error and @extended after the function call. Print these to console!

- Add many short ConsoleWrite messages so you know what your app is doing. I usually do something like this:

_d("Setting vars")
; set some variables

_d("Starting main loop")
while 1
   _d("Iteration main loop")
   ; some functions
wend

; some functiosn, again with _d inside.

Func _d($s)
  ConsoleWrite($s & @CRLF)
EndFunc

And lastly:

- Sleep over it. This is a tried and proven method for solving problems, so use it!

I wish you the best of luck. Please don't hesitate to ask any other questions you have.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0