Jump to content

cycle through a folder


sbrady
 Share

Recommended Posts

I have a GUI working that opens folders when you click a the buttons. Now I need a way to cycle through the folder items and do certain things with certain types of items, like files and sub folders. How do you cycle through a folder if you know the path.

Link to comment
Share on other sites

  • Moderators

sbrady,

Dog eaten your Help file? ;)

_FileListToArray will get the contents of the folder into an array - you can then loop through them very easily. If you do differnt things to the items depending on whether they are folders or files, you might find it easier to run the function twice and look for the files and folders separately - look at teh Help file to see how to get different returns. :)

If you want to look into the whole tree in one pass then I recommend looking at the RecFileListToArray UDF in my sig. ;)

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

having trouble looping through a folder, any chance someone is feeling nice and can help me by showing me the code I need. I obviously do not understand the help file syntax.

#include <File.au3>
#include <Array.au3>
Local $FileList = _FileListToArray("C:\Documents and Settings\sebrad\Desktop\shawn\Nuendo Projects\Promos")
;For $FileList = 1 To $FileList Step 1
;   MsgBox(0, "Count down!", $FileList)
;Next

;#cs
If @error = 1 Then
    ;MsgBox(0, "", "No Folders Found.")
    Exit
EndIf
If @error = 4 Then
    ;MsgBox(0, "", "No Files Found.")
    Exit
EndIf
;_ArrayDisplay($FileList, "$FileList")
;#ce

Local $FileList2 = 0
While $FileList2 <= 10
    MsgBox(0, "Value of $i is:", $FileList2)
    $FileList2 = $FileList2 + 1
WEnd
Link to comment
Share on other sites

You're still writing your for loop wrong in regards to looping through the array. The reason it partially works is because there's a bug in AutoIt that allows you do what you're doing, even if you're doing it wrong.

Try this example, this should work correctly, and without using a bug to do it.

#include <File.au3>
#include <Array.au3>
Local $FileList = _FileListToArray(@DesktopDir & "shawnNuendo ProjectsPromos")
$Error = @error
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $Error = ' & $Error & @crlf & '>Error code: ' & @error & @crlf) ;### Debug Console
If $Error = 1 Then
    MsgBox(0, "", "No Folders Found.")
    Exit
ElseIf $Error = 4 Then
    MsgBox(0, "", "No Files Found.")
    Exit
EndIf
For $I = 1 To $FileList[0] Step 1
  MsgBox(0, "Count down!", $FileList[$I])
Next

;#cs
_ArrayDisplay($FileList, "$FileList")
;#ce

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

Brew, thanks, here is what I am after.

this line will give me all items in the Promos folder:

Local $FileList = _FileListToArray(@DesktopDir & "shawnNuendo ProjectsPromos")

I need something like this, I know this is NOT AutoIT syntax but I think you will understand what I am getting at.

repeat with an_item in $FileList

if name of an_item contains "MIM" then

rename an_item

end if

end repeat

how do I put an if-then statement while looping through every item in the $filelist

thanks a lot if you can help me out on this one.

Link to comment
Share on other sites

  • Moderators

sbrady/

_FileListToArray returns the number of items in the [0] element, so you can use that to loop through the other elements. Looking for "MIM" means using StringInStr. So you get something like this:

; List the contents
Local $FileList = _FileListToArray(@DesktopDir & "shawnNuendo ProjectsPromos") 

For $i = 1 To $FileList[0]                        ; As explained the [0] element holds the count
    If StringInStr($aFileList[$i], "MIM") Then    ; Does the name hold the string "MIM"?
        ; Here you need to move the file
        FileMove(...)
    EndIf
next

But what do you need to do to folders? FileMove will not work on them. Should you be limiting the list to files only? :huh:

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

here is what I got to work the way I needed. The lightbulb has finally gone off.

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


; List the contents
Local $FileList = _FileListToArray(@DesktopDir & "\shawn\Nuendo Projects\Promos")


For $i = 1 To $FileList[0] ; As explained the [0] element holds the count
MsgBox(8192, "Test", $FileList[$i])

If StringInStr($FileList[$i], "Folder") Then ; Does the name hold the string "MIM"?

DirRemove ( @DesktopDir & "\shawn\Nuendo Projects\Promos\" & $FileList[$i] )



; Here you need to move the file

;FileMove(...)

EndIf

next
Link to comment
Share on other sites

  • Moderators

sbrady,

The lightbulb has finally gone off

Hurrah!! :)

One point - as it seems you are only looking for folders, why not get only folders returned from the search? Look at the $iFlag parameter in _FileListToArray to see how you can do this. ;)

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

OK, I have come a long way and a lot of things are working. Here is one that is NOT.

I have a source folder with 4 files, and 4 folders in it. I cycle through the folder and if a sub folder's name contains "EXPORTS", copy that whole sub folder to the destination folder.

All I get are the CONTENTS of the 1st folder copied over. My message box shows me I have the path right but I am doing SOMETHING wrong........who can see my error........I cant.

Local $FileList2 = _FileListToArray("\\10.10.44.37\Incoming Projects DAW1\Promos\Open PM")
For $i = 1 To $FileList2[0] ; As explained the [0] element holds the count
If StringInStr($FileList2[$i], "EXPORTS") Then    ; Does the name hold the string "EXPORTS"?
     MsgBox(8192, "COPY THIS", "\\10.10.44.37\Incoming Projects DAW1\Promos\Open PM\" & $FileList2[$i])
  DirCopy ( "\\10.10.44.37\Incoming Projects DAW1\Promos\Open PM\" & $FileList2[$i] ,@DesktopDir & "\Open PM3\" )
    EndIf
next
Link to comment
Share on other sites

this does not move the file

DirCopy does not work either.

#include 
#include 


Local $FileList = _FileListToArray("10.10.44.37Incoming Projects DAW1PromosOpen PM")

For $i = 1 To $FileList[0] ; As explained the [0] element holds the count

If StringInStr($FileList[$i], "EXPORTS") Then ; Does the name hold the string "Promo"?
MsgBox(8192, "Test", $FileList[$i])
DirMove ("10.10.44.37Incoming Projects DAW1PromosOpen PM" & $FileList[$i], @DesktopDir & "Open PM3")
EndIf
Next
Link to comment
Share on other sites

source dir Path of the source directory (with no trailing backslash). e.g. "C:Path1"

dest dir Path of the destination dir (with no trailing backslash). e.g. "C:Path_Copy"

Help file, read it.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

do you see a trailing back slash after 11-20-12 NDP EXPORTS.........well do you????????? read it

i've tried to be nice to you, I've tried to help you, but you are the most ignorant SOB I've ever run across and that's saying a LOT.

You don't read the help file, you don't read the posts that people make that try to help you, you just want people to do the work for you because you're too f**king stupid to do it yourself. You're on your own from now on.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

really, promise.

free at last, free at last

thank God almighty I'm free at last

I hope you're a man of your word

i've tried to be nice to you, I've tried to help you, but you are the most ignorant SOB I've ever run across and that's saying a LOT.

You don't read the help file, you don't read the posts that people make that try to help you, you just want people to do the work for you because you're too f**king stupid to do it yourself. You're on your own from now on.

Link to comment
Share on other sites

  • Moderators

After which this seems the only sensible thing to do........

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

Guest
This topic is now closed to further replies.
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...