Jump to content

Delete Files from different Dirs?


Recommended Posts

Hi there,

how can i delete files from different Dirs, with a MsgBox how much and where Files was deleted? Found already different Examples (_FileLisToArray), but can't sort to a working one :blink:

For example...

File is called file*.zip

Dirs are drive:\myprog\1\, drive:\myprog\2\, drive:\myprog\3\, drive:\myprog\4\

If is ready a MsgBox should show...

23 Files deleted...

8 from myprog\1\

9 from myprog\2\

4 from myprog\3\

2 from myprog\4\

Thx!

Link to comment
Share on other sites

  • Moderators

Hi, Shocker. I would suggest using Melba's RecFileListToArray from the Examples section of this forum. You could easily do something like this:

#include <Array.au3>
#include <RecFileListToArray.au3>

Local $aArray = _RecFileListToArray("C:\MyProg", "File*.zip", 1, 1, 1)
   _ArrayDisplay($aArray)

You could then loop through the array and delete them:

For $i = 1 To $aArray[0]
  FileDelete($aArray[$i])
 Next

and finally, display your message box:

MsgBox(0, "File Delete", "Deleted " & $i & " files.")

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

  • Moderators

As I mentioned, RecFileListToArray is in the Examples section - see here

As for the FileListToArrayRecursive, try a forum search for that one.

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

  • Moderators

Shocker,

Searching that number of folders and files will always take a fair time. Could you post the code you used with RecFileListToArray - I might be able to suggest a way to speed up the process. :)

But no promises. ;)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

Link to comment
Share on other sites

@M23

Thx for Reply! RecFileListToArray works fine, no ask! But made a small mistake, Folders are...

[drive:]\myprog\1\myupdate

[drive:]\myprog\2\myupdate

[drive:]\myprog\3\myupdate

[drive:]\myprog\4\myupdate

and only there are file*.zip to find. So i think it´s time wasting to search complete \myprog

Would also like a MsgBox who show how much Files(all) and from which Dirs will be deleted.

MsgBox(64,"Search...", "27 Files found." & @CRLF & @CRLF & "(10) in [drive:]\myprog\1\myupdate" &@CRLF& "(7) in [drive:]\myprog\2\myupdate" &@CRLF& "(5) in [drive:]\myprog\3\myupdate" &@CRLF& "(5) in [drive:]\myprog\4\myupdate")
Link to comment
Share on other sites

  • Moderators

Shocker,

If those paths are literals, then you can do something like this to search just those folders: ;)

#include <Array.au3>

#include <RecFileListToArray.au3>

Global $aList[1] = [0]

$sRoot = "Myprog\"

For $i = 1 To 4

    $aFolderList = _RecFileListToArray($sRoot & $i , "*.zip", 1, 0, 0, 2)

    _ArrayDisplay($aFolderList) ; Just to show result

    $aList[0] += $aFolderList[0]
    _ArrayConcatenate($aList, $aFolderList, 1)

Next

_ArrayDisplay($aList) ; Just to show result

Any use? :huh:

M23

Edit: I realised that you needed to return the full path for each file as you wee looking in different folders - the parameters have been amended to do this. :)

Edited by Melba23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

Link to comment
Share on other sites

  • Moderators

Shocker,

No doubt there are no files in that folder - so add some errorchecking to make sure you have an array returned before you access it. Somehting like this should do the trick: ;)

If Not @error Then
    $aList[0] += $aFolderList[0]
    _ArrayConcatenate($aList, $aFolderList, 1)
EndIf

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

Link to comment
Share on other sites

@M23

Thx for Reply! Without Update in _RecFileListToArray($sRoot & $i & "update", "*.zip", 1, 0, 0, 2) it dosn't work.

I thought of something like...

#include
#include

$drive = "C:"

$all = 'file*.zip'

Global $dir[4]
$dir[0] = '\myprog\1\Update'
$dir[1] = '\myprog\2\Update'
$dir[2] = '\myprog\3\Update'
$dir[3] = '\myprog\4\Update'

For $i = 0 to UBound($dir) -1
$files=_FileListToArray($drive & $dir[$i] & "\", $all)
_ArrayDisplay($files)
Next

But how can i save $files[0] for every Round and add for a complete result?

Edited by Shocker
Link to comment
Share on other sites

  • Moderators

Shocker,

it dosn't work

Not a very helpful statement. What does not work? :huh:

At the moment the UDF is only looking in the folder you pass which is what you asked me to do - I did say "If those paths are literals". Now you say that "Without Update" you do not get what you expect - what folders do you want the UDF to search? It will search in subfolders to any level if you set the parameters correctly. So how about some useful comments on where exactly you want the UDF to look for .zip files rather then just telling me it does not work - which many years of experience with this UDF tells me is not likely. ;)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

Link to comment
Share on other sites

Not a very helpful statement.

Sry, my mistake.

#include <Array.au3>

#include <RecFileListToArray.au3>

Global $aList[1] = [0]

$sRoot = "c:\Myprog\"

For $i = 1 To 4

$aFolderList = _RecFileListToArray($sRoot & $i , "*.zip", 1, 0, 0, 2)

_ArrayDisplay($aFolderList) ; Just to show result

If Not @error Then
$aList[0] += $aFolderList[0]
_ArrayConcatenate($aList, $aFolderList, 1)
EndIf

Next

Nothing happen, Array shows [0] 0

#include <Array.au3>

#include <RecFileListToArray.au3>

Global $aList[1] = [0]

$sRoot = "c:\Myprog\"

For $i = 1 To 4

    $aFolderList = _RecFileListToArray($sRoot & $i & "\update", "*.zip", 1, 0, 0, 2)

    _ArrayDisplay($aFolderList) ; Just to show result

    $aList[0] += $aFolderList[0]
    _ArrayConcatenate($aList, $aFolderList, 1)

Next

_ArrayDisplay($aList) ; Just to show result

Show *.zip's from all single Folders and a complete finally.

Edited by Shocker
Link to comment
Share on other sites

  • Moderators

Shocker,

As I explained, you need to tell the UDF if it is to search in subfolders. At the moment that first script is only looking in the Root1, Root2, Root3 & Root4 folders - not in their subfolders. If you want it to search in the subfolders you need to set the $iRecur parameter like this:

; What you have now
$aFolderList = _RecFileListToArray($sRoot & $i , "*.zip", 1, 0, 0, 2)

; What you need to have
$aFolderList = _RecFileListToArray($sRoot & $i , "*.zip", 1, 1, 0, 2)

Now the UDF will seach in all the subfolders within the Root1, Root2, Root3 & Root4 folders - which includes update - and so you should find your files. Of course it will also find any other files matching the mask - so be careful. ;)

Anyway give the script a try with the change I suggested and see if that does the trick for you. :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

Link to comment
Share on other sites

  • Moderators

Shocker,

If you want to know how many files were in each folder, why not use the UDF on each folder in turn as you did in the first place? Then it is easy to get the number of files in each folder. :)

If you use the recursive mode of the UDF to look in every folder then it returns only one array and you will have to parse that array to find out how many files were found in each folder. :(

So you choose - either look in all folders and parse the result:

#include <Array.au3>

#include <RecFileListToArray.au3>

$sRoot = "c:\Myprog\"

; Look for files in all subfolders
$aFullList = _RecFileListToArray($sRoot, "*.zip", 1, 1, 0, 2)

_ArrayDisplay($aFullList) ; Just to show result

; Declare an array to hold the number of files found
Global $aCount[5]
; Loop through the files found
For $i = 1 To $aFullList[0]
    ; Now loop through the 4 folders
    For $j = 1 To 4
        ; If the path is in the filename
        If StringInStr($aFullList[$i], $sRoot & $j) Then
            ; Add it t0 the count
            $aCount[$j] += 1
        EndIf
    Next
Next

; And display the result of the count
MsgBox(0, "Files found", _
            "Folder Myprog\1: " & $aCount[1] & @CRLF & _
            "Folder Myprog\2: " & $aCount[2] & @CRLF & _
            "Folder Myprog\3: " & $aCount[3] & @CRLF & _
            "Folder Myprog\4: " & $aCount[4])

Or look in each folder separately:

#include <Array.au3>

#include <RecFileListToArray.au3>

$sRoot = "c:\Myprog\"

; Declare an array to hold the number of files found
Global $aCount[5]

; Loop through the folders
For $i = 1 To 4

    ; Look for files in each folder
    $aFolderList = _RecFileListToArray($sRoot & $i & "\update", "*.zip", 1, 0, 0, 2)

    _ArrayDisplay($aFolderList) ; Just to show result

    ; Add count to array
    $aCount[$i] = $aFolderList[0]

Next

; And display the result of the count
MsgBox(0, "Files found", _
            "Folder Myprog\1: " & $aCount[1] & @CRLF & _
            "Folder Myprog\2: " & $aCount[2] & @CRLF & _
            "Folder Myprog\3: " & $aCount[3] & @CRLF & _
            "Folder Myprog\4: " & $aCount[4])

Sorted now? :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

Link to comment
Share on other sites

@M23

Thx for reply - it works like a charm!!! Many thx... Posted Image

Can you tell me last, how i can delete Files from Array (after MsgBox)?

$aAll = $aCount[1]+$aCount[2]+$aCount[3]+$aCount[4]

Switch MsgBox(0+4, "Found...", $aAll & " Files found" &@CRLF& @CRLF& _
"Folder Myprog\1: " & $aCount[1] & @CRLF & _
"Folder Myprog\2: " & $aCount[2] & @CRLF & _
"Folder Myprog\3: " & $aCount[3] & @CRLF & _
"Folder Myprog\4: " & $aCount[4] &@CRLF& @CRLF& _
"Delete?")
Case 6
EndSwitch
Link to comment
Share on other sites

  • Moderators

Shocker,

Of course. :)

Loop through the array of files that you get and use FileDelete or FileRecycle. But if you use the recursive version of the script you will need to check that the files come from the correct folders - remember that the UDF searches ALL the subfolders. ;)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

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...