Sign in to follow this  
Followers 0
sbrady

loop through a folder

5 posts in this topic

I have a need to loop through a folder and open the folders contained within.

the master folder is "10.10.44.160Daily 700 Club PromosAudio ExportsPM Exports

the folders within are named as such:

03-27-14 OPEN EXPORTS

03-27-14 NDP EXPORTS

here is code I used to:

1 get todays date

2. loop through the master folder

3. open and place the 2 folders from above

ITS NOT WORKING.......any ideas.

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

; month
$the_month = @MON ;12

;the day
$the_day = @mday ;18

;the year
$the_year = @YEAR ;2012
$the_year2 = StringTrimLeft ($the_year,2);12

local $todays_date = $the_month & "-" & $the_day & "-" & $the_year2 ;12-18-12
MsgBox (4096, "The Date", $todays_date);12-18-12



;------------------------------------
$open_exports_folder = "\\10.10.44.160\Daily 700 Club Promos\Audio Exports\PM Exports\" & $todays_date & " OPEN EXPORTS"
;-------------------------------------




; List the contents
Local $FileList = _FileListToArray("\\10.10.44.160\Daily 700 Club Promos\Audio Exports\PM Exports\")

For $i = 1 To $FileList[0]         ; As explained the [0] element holds the count
If StringInStr($FileList[$i], $todays_date & " OPEN EXPORTS") Then    ; Does the name hold the string "OPEN EXPORTS"?

;open OPEN EXPORTS
ShellExecute($open_exports_folder)
$thepath1 = ($open_exports_folder)
$hHandle3 = WinWait("", $thepath1)
WinMove($hHandle3, "", 50, 600, 400, 500)

EndIf
next

Share this post


Link to post
Share on other sites



Are you getting your File List in your Array?? You can check it with _ArrayDisplay($FileList). Once you know for sure you have your file list, In your For, To loop, you need to Step through your loop. Something like this

For $i =  UBound($FileList) -1  To 0 Step -1
;**Your code Goes here**

Next

I always use a UBound To get my array count.

**Remember that the value returned by UBound() is one greater than the index of an array's last element!**

That's why I use UBound($File) -1

Share this post


Link to post
Share on other sites

here is the code I am using to open 7 folders and place and size the windows when they open. Its not working.

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





; month
$the_month = @MON ;12

;the day
$the_day = @mday ;18

;the year
$the_year = @YEAR ;2012
$the_year2 = StringTrimLeft ($the_year,2);12

local $todays_date = $the_month & "-" & $the_day & "-" & $the_year2 ;12-18-12
;------------------------------------
$promo_name_NPR = $todays_date & " Promos NPR"  ;the NPR folder
$open_exports_folder = "\\10.10.44.160\Daily 700 Club Promos\Audio Exports\PM Exports\" & $todays_date & " OPEN EXPORTS"
$open_ndp_folder = "\\10.10.44.160\Daily 700 Club Promos\Audio Exports\PM Exports\"  & $todays_date & " NDP EXPORTS"
$open_bumper_Folder = "\\10.10.44.160\Daily 700 Club Promos\Audio Exports\PM Exports\" &  $todays_date & " BUMPERS EXPORTS"
;-------------------------------------




local $todays_date = $the_month & "-" & $the_day & "-" & $the_year2 ;12-18-12
;MsgBox (4096, "The Date", $todays_date);12-18-12
;DirCreate("E:\Nuendo_Projects_DAW3\700 Club Promos\" & $promo_name_NPR) ; EGR123 Schools v1 NPR



$PM_exports = "\\10.10.44.160\Daily 700 Club Promos\Audio Exports\PM Exports"
$promo_AM_NPR_Folder = "E:\Nuendo_Projects_DAW3\700 Club Promos\Promo AMs"
$1030view = "R:"
$the_promos_NPR = "E:\Nuendo_Projects_DAW3\700 Club Promos\"
$New_promo_NPR_Folder = "E:\Nuendo_Projects_DAW3\700 Club Promos\" & $promo_name_NPR



;open PM exports
ShellExecute($PM_exports )
$thepath1 = ($PM_exports )
$hHandle1 = WinWait("", $thepath1)
WinMove($hHandle1, "", 50, 600, 400, 500)




;open promos
ShellExecute($the_promos_NPR )
$thepath2 = ($the_promos_NPR )
$hHandle2 = WinWait("", $thepath2)
WinMove($hHandle2, "", 650, 600, 400, 500)




;open 1030view
ShellExecute($1030view )
$thepath3 = ($1030view )
$hHandle3 = WinWait("", $thepath3)
WinMove($hHandle3, "", 1250, 600, 400, 500)




;open AMs folder
ShellExecute($promo_AM_NPR_Folder )
$thepath4 = ($promo_AM_NPR_Folder )
$hHandle4 = WinWait("", $thepath4)
WinMove($hHandle4, "", 1850, 600, 400, 500)







; List the contents
Local $FileList = _FileListToArray("\\10.10.44.160\Daily 700 Club Promos\Audio Exports\PM Exports\")

For $i = 1 To $FileList[0]         ; As explained the [0] element holds the count
If StringInStr($FileList[$i], $todays_date & " OPEN EXPORTS") Then    ; Does the name hold the string "OPEN EXPORTS"?

;open OPEN EXPORTS
ShellExecute($open_exports_folder)
$thepath5 = ($open_exports_folder)
$hHandle5 = WinWait("", $thepath5)
WinMove($hHandle5, "", 50, 80, 600, 500)

ElseIf StringInStr($FileList[$i], $todays_date & " NDP EXPORTS") Then

;open NDP EXPORTS
ShellExecute($open_ndp_folder)
$thepath6 = ($open_ndp_folder)
$hHandle6 = WinWait("", $thepath6)
WinMove($hHandle6, "", 690, 80, 600, 500)


ElseIf StringInStr($FileList[$i], $todays_date & " BUMPERS EXPORTS") Then

;open BUMPERS EXPORTS
ShellExecute($open_bumper_Folder)
$thepath7 = ($open_bumper_Folder)
$hHandle7 = WinWait("", $thepath7)
WinMove($hHandle7, "", 1320, 80, 600, 500)


EndIf
next


;ClipPut ( $todays_date & " Promos" )




;Open Media Encoder
;ShellExecute("C:\Program Files\Adobe\Adobe Media Encoder CS5.5\Adobe Media Encoder.exe")


;Open FileZilla
;ShellExecute("C:\Program Files (x86)\FileZilla FTP Client\filezilla.exe")


;Open Premiere
;ShellExecute("E:\Docs from C\Premiere Templates\Templates foe AMs.prproj")

Share this post


Link to post
Share on other sites

 You need to make sure you have the correct data that you want in your array

** I always check mine with _ArrayDisplay**

Look at the Parameters in the function and adjust them as needed. The "How To" is in the help file.

I commented out your code and basically just put together a quick loop.  Make sure you have the correct path. You should get a Complete list of everything in the folder (Files and Folders) if you don't set any parameters in the function.

Me personally, I always use a UBound to get the total size of an array.

This method will count up the array

Example: 0,1,2,3,4,5, etc....

For $i = 0 To UBound($FileList) -1

This method will count down or backwards

Example: 5,4,3,2,1,0

$FileList = _FileListToArray("\\10.10.44.160\Daily 700 Club Promos\Audio Exports\PM Exports\")

_ArrayDisplay($FileList)

_ArrayDelete($FileList,0)

For $i = UBound($FileList) -1 To 0 Step -1

    MsgBox(0,"File Name", "This is the File Name " & @CR & $FileList[$i] & @CR & "in this position" & @CR & $i & @CR &  "in your array")

;~ If StringInStr($FileList[$i], $todays_date & " OPEN EXPORTS") Then    ; Does the name hold the string "OPEN EXPORTS"?

;~ ;open OPEN EXPORTS
;~ ShellExecute($open_exports_folder)
;~ $thepath5 = ($open_exports_folder)
;~ $hHandle5 = WinWait("", $thepath5)
;~ WinMove($hHandle5, "", 50, 80, 600, 500)

;~ ElseIf StringInStr($FileList[$i], $todays_date & " NDP EXPORTS") Then

;~ ;open NDP EXPORTS
;~ ShellExecute($open_ndp_folder)
;~ $thepath6 = ($open_ndp_folder)
;~ $hHandle6 = WinWait("", $thepath6)
;~ WinMove($hHandle6, "", 690, 80, 600, 500)


;~ ElseIf StringInStr($FileList[$i], $todays_date & " BUMPERS EXPORTS") Then

;~ ;open BUMPERS EXPORTS
;~ ShellExecute($open_bumper_Folder)
;~ $thepath7 = ($open_bumper_Folder)
;~ $hHandle7 = WinWait("", $thepath7)
;~ WinMove($hHandle7, "", 1320, 80, 600, 500)


;~EndIf

Next

Share this post


Link to post
Share on other sites

One other thing I noticed. It looks like your opening the same folder / file each time the the script loops through. I'm not sure what your doing with the stuff at the top of your script, but you can get the full path to the file in  your array using FileGetLongName. Something like this

MsgBox(0,"",FileGetLongName("\\10.10.44.160\Daily 700 Club Promos\Audio Exports\PM Exports\" & $FileList[$i])

Using the full path of the file, you can loop through and open it if you choose to.

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