| View previous topic :: View next topic |
| Author |
Message |
newbie_ez_question Guest
|
Posted: Wed Mar 17, 2010 9:27 pm Post subject: Get a list of filenames in a directory |
|
|
Hi, This is a very simple task for most, but difficult for me hehe:
How do i get a list of the filenames in my pc c:\temp\screenshot directory? Then save this list to c:\list.txt. I will use this list as below:
| Code: | ^j::
; write to the Array:
ArrayCount = 0
Loop, Read, C:\List.txt
{
ArrayCount += 1
Array%ArrayCount% := A_LoopReadLine
}
; read from the Array:
Loop %ArrayCount%
{
element := Array%A_Index%
MsgBox % "Element number " . A_Index . " is " . Array%A_Index%
}
Return |
|
|
| Back to top |
|
 |
HotKeyIt
Joined: 18 Jun 2008 Posts: 4652 Location: AHK Forum
|
|
| Back to top |
|
 |
Guest
|
Posted: Wed Mar 17, 2010 10:43 pm Post subject: thanks! |
|
|
Thank you HotKeyIt. It works beautifully! Here's my final codes:
| Code: | ^j::
; read screenshot directory
Loop,c:\test\*
FileAppend,%A_LoopFileFullPath%`n, C:\screenshots.txt
; write to the Array:
ArrayCount = 0
Loop, Read, C:\screenshots.txt
{
ArrayCount += 1
Array%ArrayCount% := A_LoopReadLine
}
; read from the Array:
Loop %ArrayCount%
{
element := Array%A_Index%
MsgBox % element
}
FileDelete, C:\screenshots.txt
Return |
|
|
| Back to top |
|
 |
SKAN
Joined: 26 Dec 2005 Posts: 8688
|
Posted: Thu Mar 18, 2010 3:57 am Post subject: |
|
|
| Why two loops? You may create the pseudo-Array as well as the text file from the first loop itself. |
|
| Back to top |
|
 |
|