Jump to content

Remove a directory from Temp


Recommended Posts

Hi!

I tried to remove Directory which is in a folder named stv23a.tmp or stv55t.tmp or...

This command don't work

DirRemove(@TempDir & "\stv~1.tmp\Directory\", 1)

Is correct stv~1.tmp ?

The wildcard would be "stv*.tmp", but DirRemove() doesn't accept wildcards.

Use _FileListToArray() with the flag for directories only, then loop through the array to do the deletes one at a time.

$avDirList = _FileListToArray(@TempDir & "\stv*.tmp", 2)
If IsArray($avDirList) Then
    For $n = 1 To $avDirList[0]
        $sPath = @TempDir & "\" & $avDirList[$n] & "\Directory" 
        If FileExists($sPath & "\") Then
            If DirRemove($sPath, 1) Then
                ConsoleWrite("Debug: Successfully deleted directory: " & $sPath & @LF)
            Else
                ConsoleWrite("Debug: Failed to delete directory: " & $sPath & @LF)
            EndIf
        Else
            ConsoleWrite("Debug: Directory does not exist: " & $sPath & @LF)
        EndIf
    Next
EndIf

:)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

Sorry PsaltyDS but I have this error

A few years of therapy should straighten you out... ;)

...

Oh! There was supposed to be a picture there?! I doesn't render for me. What's the error? Since I don't have your directory tree, I didn't test. So there's no telling how badly I coded that...

:)

Ahh. ChrisL has my back... thanks!

:P

Edited by PsaltyDS
Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

Still don't works.

Now the script is

#include <File.au3>
$avDirList = _FileListToArray(@TempDir & "\stv*.tmp", 2)
If IsArray($avDirList) Then
    For $n = 1 To $avDirList[0]
        $sPath = @TempDir & "\" & $avDirList[$n] & "\Directory" 
        If FileExists($sPath & "\") Then
            If DirRemove($sPath, 1) Then
                ConsoleWrite("Debug: Successfully deleted directory: " & $sPath & @LF)
            Else
                ConsoleWrite("Debug: Failed to delete directory: " & $sPath & @LF)
            EndIf
        Else
            ConsoleWrite("Debug: Directory does not exist: " & $sPath & @LF)
        EndIf
    Next
EndIf

With no errors, but the Directory folder is not remove.

This is the tree: C:\Documents and Settings\Administrator\Local Settings\Temp\stv44r.tmp\Directory

Link to comment
Share on other sites

  • Moderators

Still don't works.

Now the script is

#include <File.au3>
$avDirList = _FileListToArray(@TempDir & "\stv*.tmp", 2)
If IsArray($avDirList) Then
    For $n = 1 To $avDirList[0]
        $sPath = @TempDir & "\" & $avDirList[$n] & "\Directory" 
        If FileExists($sPath & "\") Then
            If DirRemove($sPath, 1) Then
                ConsoleWrite("Debug: Successfully deleted directory: " & $sPath & @LF)
            Else
                ConsoleWrite("Debug: Failed to delete directory: " & $sPath & @LF)
            EndIf
        Else
            ConsoleWrite("Debug: Directory does not exist: " & $sPath & @LF)
        EndIf
    Next
EndIfoÝ÷ ØƲmë!¢é]m殶­seôfÆTÆ7EFô'&FV×F"ÂgV÷C·7Gb¢çF×gV÷C²Â"
?
Edited by SmOke_N

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

Still don't works.

With no errors, but the Directory folder is not remove.

This is the tree: C:\Documents and Settings\Administrator\Local Settings\Temp\stv44r.tmp\Directory

Does @TempDir = "C:\Documents and Settings\Administrator\Local Settings\Temp"?

:)

@SmOke_N: Doh! ;)

Edited by PsaltyDS
Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

  • Moderators

Does @TempDir = "C:\Documents and Settings\Administrator\Local Settings\Temp"?

:)

Check out my edit PDS.

EDIT:

I'll just add it here what I think might work:

#include <File.au3>
;#include <array.au3>
$avDirList = _FileListToArray(@TempDir, "stv*.tmp", 2)
;_ArrayDisplay($avDirList)
If IsArray($avDirList) Then
    For $n = 1 To $avDirList[0]
        $sPath = @TempDir & "\" & $avDirList[$n]
        If FileExists($sPath & "\") Then
            If DirRemove($sPath, 1) Then
                ConsoleWrite("Debug: Successfully deleted directory: " & $sPath & @LF)
            Else
                ConsoleWrite("Debug: Failed to delete directory: " & $sPath & @LF)
            EndIf
        Else
            ConsoleWrite("Debug: Directory does not exist: " & $sPath & @LF)
        EndIf
    Next
EndIf
I wasn't quite sure what the extra "\Directory" being added on was. Edited by SmOke_N

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

This is the tree: C:\Documents and Settings\Administrator\Local Settings\Temp\stv44r.tmp\Directory\

and with this script it works:

#include <File.au3>
;#include <array.au3>
$avDirList = _FileListToArray(@TempDir, "stv*.tmp", 2)
;_ArrayDisplay($avDirList)
If IsArray($avDirList) Then
    For $n = 1 To $avDirList[0]
        $sPath = @TempDir & "\" & $avDirList[$n] & "\Directory"
        If FileExists($sPath & "\") Then
            If DirRemove($sPath, 1) Then
                ConsoleWrite("Debug: Successfully deleted directory: " & $sPath & @LF)
            Else
                ConsoleWrite("Debug: Failed to delete directory: " & $sPath & @LF)
            EndIf
        Else
            ConsoleWrite("Debug: Directory does not exist: " & $sPath & @LF)
        EndIf
    Next
EndIf

Thank you guys!

Edited by ffdshow
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...