yaqwa Posted September 18, 2009 Report Share Posted September 18, 2009 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. Quote Link to comment Share on other sites More sharing options...
Cory Posted September 18, 2009 Report Share Posted September 18, 2009 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. Quote Link to comment Share on other sites More sharing options...
yaqwa Posted September 18, 2009 Author Report Share Posted September 18, 2009 This is a temporary Folder - so i really do not know what is inside :-))) So i think the first one could be better - but i really do not know how to do this. So help please or an other idea? Quote Link to comment Share on other sites More sharing options...
Cory Posted September 22, 2009 Report Share Posted September 22, 2009 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/> Quote Link to comment Share on other sites More sharing options...
yaqwa Posted September 24, 2009 Author Report Share Posted September 24, 2009 Working - thanks a lot But now - how about those subfolders? Problem is that they also exists - i do not know the names and they have files inside. I can delete the files in the subfolders - no problem but how can i delete the empty folders than? Quote Link to comment Share on other sites More sharing options...
Cory Posted September 24, 2009 Report Share Posted September 24, 2009 Do another "Repeat With Folder", return folder names instead and delete the folders instead. Quote Link to comment Share on other sites More sharing options...
yaqwa Posted September 25, 2009 Author Report Share Posted September 25, 2009 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? Quote Link to comment Share on other sites More sharing options...
Cory Posted September 25, 2009 Report Share Posted September 25, 2009 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. Quote Link to comment Share on other sites More sharing options...
yaqwa Posted September 25, 2009 Author Report Share Posted September 25, 2009 i tried the first one is working - the second one not. It still tells me that there are files open who can not be deleted. Quote Link to comment Share on other sites More sharing options...
Cory Posted September 25, 2009 Report Share Posted September 25, 2009 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? Quote Link to comment Share on other sites More sharing options...
yaqwa Posted September 26, 2009 Author Report Share Posted September 26, 2009 the suggestion - sorry i do not understand what exactly you mean. Your codes: I used both but the second one gives me a error in line 3 and Win7 told me that there are some Folders which could not be deleted. Quote Link to comment Share on other sites More sharing options...
Cory Posted September 26, 2009 Report Share Posted September 26, 2009 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. Quote Link to comment Share on other sites More sharing options...
yaqwa Posted September 27, 2009 Author Report Share Posted September 27, 2009 working now with the second suggestion thanks a lot Quote Link to comment Share on other sites More sharing options...
Cory Posted September 28, 2009 Report Share Posted September 28, 2009 You know you could do the file deletion with a console command as well. EG "DEL c:\temp /S /Q" Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.