AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Get a list of filenames in a directory

 
Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
newbie_ez_question
Guest





PostPosted: Wed Mar 17, 2010 9:27 pm    Post subject: Get a list of filenames in a directory Reply with quote

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

PostPosted: Wed Mar 17, 2010 9:54 pm    Post subject: Reply with quote

Code:
Loop,c:\temp\screenshot\*
 FileAppend,%A_LoopFileFullPath%`n,C:\List.txt

_________________
AHK_H (2alpha) AHF TT _Struct WatchDir Yaml _Input ObjTree RapidHotkey DynaRun Wink
Back to top
View user's profile Send private message
Guest






PostPosted: Wed Mar 17, 2010 10:43 pm    Post subject: thanks! Reply with quote

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

PostPosted: Thu Mar 18, 2010 3:57 am    Post subject: Reply with quote

Why two loops? You may create the pseudo-Array as well as the text file from the first loop itself.
Back to top
View user's profile Send private message Send e-mail
Display posts from previous:   
Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group