Sign in to follow this  
Followers 0

DirRemove Question

11 posts in this topic

#1 ·  Posted (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 by vim

Share this post


Link to post
Share on other sites



#2 ·  Posted

What is your problem exactly? I see no question mark.

Share this post


Link to post
Share on other sites

#3 ·  Posted (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 by vim

Share this post


Link to post
Share on other sites

#4 ·  Posted (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 by BPBNA

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

EDIT OUT

Edited by vim

Share this post


Link to post
Share on other sites

#6 ·  Posted

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.

Share this post


Link to post
Share on other sites

#7 ·  Posted (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 by BPBNA

Share this post


Link to post
Share on other sites

#8 ·  Posted

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

Share this post


Link to post
Share on other sites

#9 ·  Posted (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.

:whistle:

Edit:

Updated to reflect new AutoIt release version.

Edited by MHz

Share this post


Link to post
Share on other sites

#10 ·  Posted

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.

Share this post


Link to post
Share on other sites

#11 ·  Posted

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?

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