Jump to content
Macro Express Forums

Please help with temporary Folder


Recommended Posts

Hi

I want to delete all files in my temp folder and than shut down. I can create a macro just with "delete files or folders" c:\temp but he stops at the first file who cannot be deleted because it is in use.

So how can i set up this macro so he deletes all files and Subfolders in c:\temp except (skips) those who are in use.

Link to comment
Share on other sites

Two possible methods. First you might try modifying the error handler (On Error tab) to skip instead of Halt Macro. I have never tried this so you would need to test it. Second would be to do a Repeat With Folder command and get the name of each file and perform delete on each specific file. But in that loop encapsulate the delete command in an If File Ready condition to skip those in use.

Link to comment
Share on other sites

I tried the first method and stupidly it doesn't work. Windows will prompt you that the file in in use. So much for the 'ignore error".

 

The second method is simple as well works like this:

 

Repeat with Folder C:\Users\cory.CJ\Desktop\delete me

If File Ready: "%File Name%"

Delete File/Files: "%File Name%"

End If

End Repeat

 

Of course you will want to change the path in line 1 to your temp folder. Below is the raw script you can copy and paste into your scripting editor.

<REPEAT WITH FOLDER Path="C:\\Users\\cory.CJ\\Desktop\\delete me" OnlyFiles="TRUE" Destination="%File Name%" FullPath="TRUE" ProcSubfolders="FALSE"/>
<IF FILE READY Filename="%File Name%" Use_Path="FALSE"/>
<DELETE FILE/FILES Path="%File Name%" Progress="FALSE" Recurse="FALSE" Permanent="FALSE" _IGNORE="0x0032"/>
<END IF/>
<END REPEAT/>

Link to comment
Share on other sites

I tried this:

<REPEAT WITH FOLDER Path="c:\\temp" OnlyFiles="FALSE" Destination="%Folder Name%" FullPath="TRUE" ProcSubfolders="TRUE"/>

<IF FOLDER EXISTS Path="%Folder Name%"/>

<DELETE FILE/FILES Path="%Folder Name%" Progress="FALSE" Recurse="TRUE" Permanent="FALSE" _IGNORE="0x0032"/>

<END IF/>

<END REPEAT/>

 

but it wont work because some files are in use inside the folders

 

so what am i doing wrong?

Link to comment
Share on other sites

After more consideration I was an idiot, it can't be done that simply. And apparently we don't have adequate error handlers either. Something I might write up as a feature request. So I think what you need to do is in the first loop log all the files that were not ready by appending them to a string var. Then in the second loop see if that path exists in that log of busy files dont try to delete it.

 

Repeat with Folder C:\Users\cory.CJ\Desktop\delete me
 If Variable %Busy Files% Does not Contain "%Folder Path%"
Delete Folder "%File Name%"
 End If
End Repeat

 

<REPEAT WITH FOLDER Path="C:\\Users\\cory.CJ\\Desktop\\delete me" OnlyFiles="FALSE" Destination="%Folder Path%" FullPath="TRUE" ProcSubfolders="FALSE"/>
<IF VARIABLE Variable="%Busy Files%" Condition="\x07" Value="%Folder Path%" IgnoreCase="FALSE"/>
<DELETE FOLDER Path="%File Name%"/>
<END IF/>
<END REPEAT/>

 

The other alternative is that you can issue an RD (Remove Directory) command with the External script command in the second Repeat with Folder loop. If you use the /Q (Quiet) and /S (Subdirectories and files) you wouldn't even need to check or keep track of them.

Link to comment
Share on other sites

I don't understand what you are talking about. Are you saying the delete folder loop which is second in the first suggestion or my suggestion about using the RD command. If it's the first suggesting did you modify the first loop to log the files that were busy?

Link to comment
Share on other sites

Sorry, this is kind of disjointed. My suggestion is to do two stages. First you would to the Repeat With Folder that would return files in all subdirectories. There is an If statement in there to test if the file is ready. Make the else in that condition log the file name to an accumulator variable so you will know which are in use. Then do another Repeat With Folder which returns folder names. In there have a condition if the file path to the folder is contained by that error accumulating variable to skip. The reason here is that we will not be able to delete folders which have an in use file and is therefore not empty.

 

My other suggestion was to use a console command for the second part instead. TO make a simple example open a command prompt and type "RD C:\test\temp /s /q". This is the Remove Directory command similar to the DEL (Delete) command you have used at some point. In this example the temp directory and all it's subdirectories and files will be deleted. The S parameter is for Subdirectories and files and the Q is the Quiet option that will prevent the prompt. It will report an error if a folder can not be deleted if it contains an in use file but this one is easy to ignore. How you run a command like this is using the new External Script command.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...