Jump to content

DirRemove Question


vim
 Share

Recommended Posts

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 by vim
Link to comment
Share on other sites

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 by vim
Link to comment
Share on other sites

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

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 by BPBNA
Link to comment
Share on other sites

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

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.

:whistle:

Edit:

Updated to reflect new AutoIt release version.

Edited by MHz
Link to comment
Share on other sites

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.

:whistle:

Edit:

Updated to reflect new AutoIt release version.

Link to comment
Share on other sites

  • 4 years later...

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

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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...