vim Posted August 11, 2006 Share Posted August 11, 2006 (edited) I have a short vb script that removes anything in "C:\Windows\Temp" and any directories below (Resursive) I can't get Autoit to do the same thing: $val1 = FileRecycleEmpty("C:\") $val2 = FileDelete("C:\Documents and Settings\Administrator\Local Settings\Temporary Internet Files") $val3 = FileDelete("C:\Documents and Settings\Administrator\Local Settings\Temp\*.*") $val4 = FileDelete("c:\temp\*.*") $val5 = DirRemove("c:\windows\temp\", 1) <- This removes everything INCLUDING the Temp folder ;$val5 = DirRemove("c:\windows\temp\*.*") ;Run(@ComSpec & " /k rd /s /q " & '"c:\windows\temp\"', "", @SW_HIDE) <- This removes everything INCLUDING the Temp folder ;$val5 = FileDelete("c:\windows\temp\*.*")<- This will remove what's in the Temp folder but not behond $val6 = FileDelete("C:\Documents and Settings\Administrator\Cookies") $val7 = FileDelete("C:\Documents and Settings\Administrator\Local Settings\History") ; Below is just Return Values to see what , if any was removed. MsgBox(0, "File Return Values", _ "RECYCLE BIN:" & @TAB & @TAB &$val1 & @CR & _ "TEMPORY INTERNET FILES:" & @TAB & $val2 & @CR & _ "LOCAL SETTINGS\TEMP:" & @TAB & $val3 & @CR & _ "C:\TEMP\*.*:" & @TAB & @TAB & $val4 & @CR & _ "C:\WINDOWS\TEMP\*.*:" & @TAB & $val5 & @CR & _ "COOKIES:" & @TAB & @TAB & $val6) ============================ Edited August 11, 2006 by vim Link to comment Share on other sites More sharing options...
MHz Posted August 11, 2006 Share Posted August 11, 2006 What is your problem exactly? I see no question mark. Link to comment Share on other sites More sharing options...
vim Posted August 11, 2006 Author Share Posted August 11, 2006 (edited) Sorry, but I tried to copy & paste my question. I don't know what happened. If someone can point me in the right direction. I have a question in a file and tried to copy & paste but its all messed up when I get it here. I tried to edit , but same results. Edited August 11, 2006 by vim Link to comment Share on other sites More sharing options...
BPBNA Posted August 11, 2006 Share Posted August 11, 2006 (edited) Maybe hes asking how to delete recursively or not? DirRemove("C:\MyDir", 1);==> Removes the directory and all files/subfolders DirRemove("C:\MyDir", 0);==> Only removes the directory if it is empty Edited August 11, 2006 by BPBNA Link to comment Share on other sites More sharing options...
vim Posted August 11, 2006 Author Share Posted August 11, 2006 (edited) EDIT OUT Edited August 11, 2006 by vim Link to comment Share on other sites More sharing options...
vim Posted August 11, 2006 Author Share Posted August 11, 2006 This will just have to do. Its just a snipit. I have a VBS file that does Exactly what I want it to do. I'm trying to get Autoit to duplicate the same function. The VBS snipit is this: .. .. .. DeleteFolderContent "c:\windows\temp\*.*" .. .. Sub DeleteFolderContent(FolderSpec) Dim fso Set fso = CreateObject("Scripting.FileSystemObject") On Error Resume Next 'Delete all files in folder fso.DeleteFile(FolderSpec) 'Delete all folders fso.DeleteFolder(FolderSpec) End Sub It removes anything within "C:\Windows\Temp" and below but NOT Temp itself. If nothing is in "C:\Windows\Temp" , nothing is done. Link to comment Share on other sites More sharing options...
BPBNA Posted August 11, 2006 Share Posted August 11, 2006 (edited) You could always just DirRemove("C:\windows\temp", 1) then DirCreate("C:\windows\temp"). Another way would be with FileFindFirstFile and FileFindNextFile and delete them one by one. Edit: Forgot to make the DirRemove recursive Edited August 11, 2006 by BPBNA Link to comment Share on other sites More sharing options...
vim Posted August 12, 2006 Author Share Posted August 12, 2006 BPBNA, Thanks for reply. I'll look into FileFindFirstFile,FileFindNextFile.I was just curious why VBS works intutitively?Thanks again.You could always just DirRemove("C:\windows\temp", 1) then DirCreate("C:\windows\temp"). Another way would be with FileFindFirstFile and FileFindNextFile and delete them one by one.Edit: Forgot to make the DirRemove recursive Link to comment Share on other sites More sharing options...
MHz Posted August 12, 2006 Share Posted August 12, 2006 (edited) BPBNA, Thanks for reply. I'll look into FileFindFirstFile,FileFindNextFile. I was just curious why VBS works intutitively? Thanks again.AutoIt3 v3.2 Beta has Com ability so if you are comfortable with VBS use, then you may want to convert it to the similar AutoIt syntax. Example: DeleteFolderContent("c:\windows\temp\*.*") Func DeleteFolderContent($FolderSpec) Local $fso $fso = ObjCreate("Scripting.FileSystemObject") ;Delete all files in folder $fso.DeleteFile($FolderSpec) ;Delete all folders $fso.DeleteFolder($FolderSpec) EndFunc Error handling is done with ObjEvent(), which calls a selected user defined function. Edit: Updated to reflect new AutoIt release version. Edited August 12, 2006 by MHz Link to comment Share on other sites More sharing options...
vim Posted August 12, 2006 Author Share Posted August 12, 2006 I'll be darn. That's great. So I can 'wrap' Autoit around any of my vbs scripts! I was using a crude dos menu before. Thanks!MHz AutoIt3 v3.2 Beta has Com ability so if you are comfortable with VBS use, then you may want to convert it to the similar AutoIt syntax. Example: DeleteFolderContent("c:\windows\temp\*.*") Func DeleteFolderContent($FolderSpec) Local $fso $fso = ObjCreate("Scripting.FileSystemObject") ;Delete all files in folder $fso.DeleteFile($FolderSpec) ;Delete all folders $fso.DeleteFolder($FolderSpec) EndFunc Error handling is done with ObjEvent(), which calls a selected user defined function. Edit: Updated to reflect new AutoIt release version. Link to comment Share on other sites More sharing options...
tkocsir Posted September 7, 2010 Share Posted September 7, 2010 AutoIt3 v3.2 Beta has Com ability so if you are comfortable with VBS use, then you may want to convert it to the similar AutoIt syntax. Example: DeleteFolderContent("c:\windows\temp\*.*") Func DeleteFolderContent($FolderSpec) Local $fso $fso = ObjCreate("Scripting.FileSystemObject") ;Delete all files in folder $fso.DeleteFile($FolderSpec) ;Delete all folders $fso.DeleteFolder($FolderSpec) EndFunc Error handling is done with ObjEvent(), which calls a selected user defined function. Edit: Updated to reflect new AutoIt release version. This is great! But it gives an error and stops, when I try delete a file which is running or something. It would be good to skip these kind of files and delete the other files, which can be deleted. Does anybody know how to solve this? Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now