Sign in to follow this  
Followers 0
lafafmentvotre

[RESOLVED] Deleting specific folders

18 posts in this topic

#1 ·  Posted (edited)

Hi everybody and sorry for my bad english.

I search a solution to delete folders who begins with "$NtUninstall....." and who only begin with this name in the directory "C:\Windows"

Posted Image

Is it possible ?

Thanks for help

Edited by lafafmentvotre

Share this post


Link to post
Share on other sites



lafafmentvotre,

I suggest using _FileListToArray to get all the folders matching the required name in that folder and then looping through the returned array passing each element through DirRemove. That should work. ;)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

Hello Melba23

Thanks for help

I do this

#Include <File.au3>
#Include <Array.au3>
Global $pathFolders = "C:\TESTS\"
$folderlist=_FileListToArray($pathFolders,'$NtUninstall*',2)
_ArrayDisplay($folderlist)
$i = 0
For $files in $folderlist
If $i = 0 Then
$i+=1
Else
DirRemove($pathFolders & $files, 1)
EndIf
Next

If folders "$NtUninstall....." exist, it works. But if there is not, there is an error message :

F:\Pro\AutoIt Development\Seven\Purge_XP_Computer\test.au3 (7) : ==> Variable must be of type "Object".:
For $files in $folderlist
For $files in $folderlist^ ERROR

Share this post


Link to post
Share on other sites

#3lafafmentvotre,

You just need to add some erorchecking to make sure that you have an array - something like this perhaps: :D

#include <File.au3>
#include <Array.au3>

Global $pathFolders = "C:TESTS"
$folderlist = _FileListToArray($pathFolders, '$NtUninstall*', 2)
If Not @error Then
    _ArrayDisplay($folderlist)
    For $i = 1 To $folderlist[0]
        DirRemove($pathFolders & "" & $folderlist[$i], 1)
    Next
Else
    MsgBox(0, "Ooops!", "No folders found")
EndIf

And why use the complicated For...In...Next structure when you can use the count returned in the [0] element of the array ina simple For...Next loop? ;)

All clear? :)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

Hello Melba23

All Clear but now, i have an error

F:\Pro\AutoIt Development\Seven\Purge_XP_Computer\Purge_XP_Computer.au3 (50) : ==> Array variable has incorrect number of subscripts or subscript dimension range exceeded.:
DirRemove('\\'&$arraylist[$i]&'\C$\TESTS\'&$folderlist[$i], 1)
DirRemove('\\'&^ ERROR

This is my script :

Break(1)
#region AUTOIT VARIABLES
#include <Process.au3>
#include <WindowsConstants.au3>
#include <StaticConstants.au3>
#include <File.au3>
#include <Array.au3>
#endregion
#region SCRIPT VARIABLES
$file='Purge_XP_Computer_'&@YEAR&'-'&@MON&'-'&@MDAY&'.log'
Local $rcs_directory='C$\RCS'
;~ Local $pathFolders = "C$\WINDOWS\"
Local $pathFolders = "C$\TESTS\"
$arraylist=""
$arrayfolderlist=""
#endregion
#region FILE
#endregion
#region SCRIPT
_FileReadToArray("Purge_XP_Computer.txt", $arraylist)
$GuiRun=GuiCreate("", 300, 60, -1, -1, $WS_POPUPWINDOW)
$label1=GUICtrlCreateLabel("Purge in progress for :", 0, 10, 300, 20, $SS_CENTER)
$label2=GUICtrlCreateLabel("", 0, 30, 300, 20,$SS_CENTER)
GUICtrlSetFont(-1, 9, 800)
GUISetState(@SW_SHOW,$GuiRun)
For $i=1 to Ubound($arraylist)-1
GUICtrlSetData($label2,$arraylist[$i])
$ping=Ping($arraylist[$i])
If $ping Then
;REMOVE C:\RCS
If FileExists('\\'&$arraylist[$i]&'\c$\RCS') Then
DirRemove('\\'&$arraylist[$i]&'\c$\RCS',1)
$intFile = FileOpen($file, 1)
FileWriteLine($intFile, $arraylist[$i]&' - Folder RCS was deleted on '&@YEAR&'-'&@MON&'-'&@MDAY&' at '&@HOUR&':'&@MIN&':'&@SEC)
FileClose($intfile)
EndIf
;REMOVE "$NtUninstall*" FOLDERS
$folderlist = _FileListToArray('\\'&$arraylist[$i]&'\C$\TESTS\', '$NtUninstall*', 2)
If Not @error Then
For $i = 1 To $folderlist[0]
DirRemove('\\'&$arraylist[$i]&'\C$\TESTS\'&$folderlist[$i], 1)
Next
Else
Exit
EndIf
Else
$intFile = FileOpen($file, 1)
FileWriteLine($intFile, $arraylist[$i]&' - Host is offline or unreachable')
FileClose($intfile)
EndIf
Next
GUIDelete($GuiRun)
#endregion
#region FUNCTIONS
#endregion

The TXT file contains list of computers with fqdn

Do you have an idea ?

Share this post


Link to post
Share on other sites

lafafmentvotre,

Do you have an idea ?

Yes - you are using $i for both loops - so the count value of the inner one overwrites the count value of the outer leading to the error when it exits. Use $j or similar for the inner loop - then you will keep the 2 counts separate. You will also need to adjust the index to $folderlist[$j]. ;)

By the way, if you use Tidy to get your script properly indented, the problem is much easier to spot: :)

#region SCRIPT
_FileReadToArray("Purge_XP_Computer.txt", $arraylist)
$GuiRun = GUICreate("", 300, 60, -1, -1, $WS_POPUPWINDOW)
$label1 = GUICtrlCreateLabel("Purge in progress for :", 0, 10, 300, 20, $SS_CENTER)
$label2 = GUICtrlCreateLabel("", 0, 30, 300, 20, $SS_CENTER)
GUICtrlSetFont(-1, 9, 800)
GUISetState(@SW_SHOW, $GuiRun)
For $i = 1 To UBound($arraylist) - 1 ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    GUICtrlSetData($label2, $arraylist[$i])
    $ping = Ping($arraylist[$i])
    If $ping Then
        ;REMOVE C:RCS
        If FileExists('' & $arraylist[$i] & 'c$RCS') Then
            DirRemove('' & $arraylist[$i] & 'c$RCS', 1)
            $intFile = FileOpen($file, 1)
            FileWriteLine($intFile, $arraylist[$i] & ' - Folder RCS was deleted on ' & @YEAR & '-' & @MON & '-' & @MDAY & ' at ' & @HOUR & ':' & @MIN & ':' & @SEC)
            FileClose($intFile)
        EndIf
        ;REMOVE "$NtUninstall*" FOLDERS
        $folderlist = _FileListToArray('' & $arraylist[$i] & 'C$TESTS', '$NtUninstall*', 2)
        If Not @error Then
            For $j = 1 To $folderlist[0] ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
                DirRemove('' & $arraylist[$i] & 'C$TESTS' & $folderlist[$j], 1) ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
            Next
        Else
            Exit
        EndIf
    Else
        $intFile = FileOpen($file, 1)
        FileWriteLine($intFile, $arraylist[$i] & ' - Host is offline or unreachable')
        FileClose($intFile)
    EndIf
Next
GUIDelete($GuiRun)
#endregion SCRIPT
#region FUNCTIONS
#endregion FUNCTIONS

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

Wonderful

It works fine

Many thanks M23

Share this post


Link to post
Share on other sites

lafafmentvotre,

Il n'y a pas de quoi! ;)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

when checking if _FileListToArray() returns any folders/files, I usually just check the [0] element to see if its > 0, because the function always returns a [0] element even if it doesn't find anything. Is it recommended to check @error instead?


Spoiler

“Hello, ladies, look at your man, now back to me, now back at your man, now back to me. Sadly, he isn’t me, but if he stopped using ladies scented body wash and switched to Old Spice, he could smell like he’s me. Look down, back up, where are you? You’re on a boat with the man your man could smell like. What’s in your hand, back at me. I have it, it’s an oyster with two tickets to that thing you love. Look again, the tickets are now diamonds. Anything is possible when your man smells like Old Spice and not a lady. I’m on a horse.”

 

Share this post


Link to post
Share on other sites

mechaflash213,

because the function always returns a [0] element even if it doesn't find anything

Are you sure about that? :)

#include <File.au3>

$aRet = _FileListToArray(@ScriptDir, "nothing_at_all", 2)

ConsoleWrite($aRet[0] & @CRLF)

I get a ""Subscript used with non-Array variable" error, just as the Help file says I should: ;)

Success: an Array, see remarks 
Failure: 0 
@Error:  1 = Path not found or invalid 
         2 = Invalid $sFilter 
         3 = Invalid $iFlag 
         4 = No File(s) Found

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

hmmmm... I dunno how... or why... but in one of my programs, i iterate over the folder with "*" looking for only files, and when it was an empty folder, it would return a [0] element. So I made the check If $a[0] > 0 Then (...). I used to use If IsArray($a) Then (...) but it had always returned True even if the folder was empty.

But now I just setup an empty folder and tested it and it returns the same error as what you had shown o.0 I'm confuzzled.

EDIT: interesting... IsArray() returns true when pointing to it. I'm fail =(

#include <File.au3>

$aRet = _FileListToArray(@ScriptDir, "nothing_at_all", 2)

ConsoleWrite(IsArray($aRet) & @CRLF)
Edited by mechaflash213

Spoiler

“Hello, ladies, look at your man, now back to me, now back at your man, now back to me. Sadly, he isn’t me, but if he stopped using ladies scented body wash and switched to Old Spice, he could smell like he’s me. Look down, back up, where are you? You’re on a boat with the man your man could smell like. What’s in your hand, back at me. I have it, it’s an oyster with two tickets to that thing you love. Look again, the tickets are now diamonds. Anything is possible when your man smells like Old Spice and not a lady. I’m on a horse.”

 

Share this post


Link to post
Share on other sites

mechaflash213,

Are we inhabiting the same universe? ;)

IsArray returns 0 when I run your code:

#include <File.au3>

$aRet = _FileListToArray(@ScriptDir, "nothing_at_all", 2)

ConsoleWrite(IsArray($aRet) & @CRLF)

Although not a direct Boolean, AutoIt will read that value as "False".

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

ignore me... my intelligence forgot to jump on board the S.S. BrainInSkull when I went to work this morning. Hopefully I'll be able to pick him up on my lunch break... and the bastard better not be sleeping.

1 person likes this

Spoiler

“Hello, ladies, look at your man, now back to me, now back at your man, now back to me. Sadly, he isn’t me, but if he stopped using ladies scented body wash and switched to Old Spice, he could smell like he’s me. Look down, back up, where are you? You’re on a boat with the man your man could smell like. What’s in your hand, back at me. I have it, it’s an oyster with two tickets to that thing you love. Look again, the tickets are now diamonds. Anything is possible when your man smells like Old Spice and not a lady. I’m on a horse.”

 

Share this post


Link to post
Share on other sites

mechaflash213,

I know the feeling. ;)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

Hello guys

I spoke too soon

The script works fine but just for the first computer in my txt file, it stops after the first computer.

If I use _arraydisplay to view my list, it's ok

_FileReadToArray("Purge_XP_Computer.txt", $arraylist)
_ArrayDisplay($arraylist)

Grrrrrrrrr !!!!!!!!!!!!!

Share this post


Link to post
Share on other sites

lafafmentvotre,

it stops after the first computer

Perhaps because there are no folders on that first machine (you have probably already removed them in earlier tests) and you tell it to exit? ;)

If Not @error Then
    For $j = 1 To $folderlist[0]
        DirRemove('' & $arraylist[$i] & 'C$TESTS' & $folderlist[$j], 1)
    Next
Else
    Exit ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
EndIf

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

Mouarf

I'm stupid

It works now :

If Not @error Then
            For $j = 1 To $folderlist[0] ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
                DirRemove('\\' & $arraylist[$i] & $pathFolders & $folderlist[$j], 1) ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
            $intFile = FileOpen($file, 1)
            FileWriteLine($intFile, $arraylist[$i] & ' - Folder ' & $folderlist[$j] & ' was deleted on ' & @YEAR & '-' & @MON & '-' & @MDAY & ' at ' & @HOUR & ':' & @MIN & ':' & @SEC)
            FileClose($intFile)
            Next
        Else
;~           Exit
        EndIf

Share this post


Link to post
Share on other sites

lafafmentvotre,

Nice to see the crystal ball is in good working order today! ;)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

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