Jump to content

This site uses cookies. By continuing to browse the site you are agreeing to our use of cookies. Find out more here. X
X


Photo

DirRemove Question


  • Please log in to reply
10 replies to this topic

#1 vim

vim

    Polymath

  • Active Members
  • PipPipPipPip
  • 218 posts

Posted 11 August 2006 - 09:35 PM

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, 11 August 2006 - 10:04 PM.








#2 MHz

MHz

    Just simple

  • MVPs
  • 5,725 posts

Posted 11 August 2006 - 09:47 PM

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

#3 vim

vim

    Polymath

  • Active Members
  • PipPipPipPip
  • 218 posts

Posted 11 August 2006 - 09:51 PM

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, 11 August 2006 - 09:53 PM.


#4 BPBNA

BPBNA

    Prodigy

  • Active Members
  • PipPipPip
  • 168 posts

Posted 11 August 2006 - 09:52 PM

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, 11 August 2006 - 09:55 PM.


#5 vim

vim

    Polymath

  • Active Members
  • PipPipPipPip
  • 218 posts

Posted 11 August 2006 - 09:56 PM

EDIT OUT

Edited by vim, 11 August 2006 - 10:09 PM.


#6 vim

vim

    Polymath

  • Active Members
  • PipPipPipPip
  • 218 posts

Posted 11 August 2006 - 10:00 PM

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.

#7 BPBNA

BPBNA

    Prodigy

  • Active Members
  • PipPipPip
  • 168 posts

Posted 11 August 2006 - 10:22 PM

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, 11 August 2006 - 10:22 PM.


#8 vim

vim

    Polymath

  • Active Members
  • PipPipPipPip
  • 218 posts

Posted 12 August 2006 - 02:15 AM

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



#9 MHz

MHz

    Just simple

  • MVPs
  • 5,725 posts

Posted 12 August 2006 - 09:43 AM

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, 12 August 2006 - 10:45 AM.


#10 vim

vim

    Polymath

  • Active Members
  • PipPipPipPip
  • 218 posts

Posted 12 August 2006 - 03:46 PM

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.



#11 tkocsir

tkocsir

    Seeker

  • Active Members
  • 33 posts

Posted 07 September 2010 - 01:22 PM

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?




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users