Page 1 of 1
How to list the files inside a folder
Posted: Wed Jan 13, 2016 9:39 am
by shalu
Hi ALL,
How to list the files inside a folder without the choose the location.
eg:
put"D:\test\an" into content
I want to list the content of "D:\test\an" into a variable is it possible . I am using windows system

Re: How to list the files inside a folder
Posted: Wed Jan 13, 2016 10:08 am
by jmburnod
Hi Shalu,
This function return the list of files in a folder without ".*" :
Code: Select all
function getFilesInFol tFol
put empty into rFilesInFol
if there is a folder tFol then
set the defaultFolder to tFol
put the files into rFilesInFol
filter rFilesInFol without ".*"
end if
return rFilesInFol
end getFilesInFol
Best regards
Jean-Marc
Re: How to list the files inside a folder
Posted: Wed Jan 13, 2016 11:49 am
by Klaus
Hi all,
to avoid eventual surprises, I would add two lines:
Code: Select all
function getFilesInFol tFol
put empty into rFilesInFol
if there is a folder tFol then
put the folder into tOldDir
set the folder to tFol
put the files into rFilesInFol
filter rFilesInFol without ".*"
set the folder to tOldDir
end if
return rFilesInFol
end getFilesInFol
Best
Klaus
Re: How to list the files inside a folder
Posted: Thu Jan 14, 2016 2:13 am
by FourthWorld
A lot of folks (including myself) have been caught with unexpected recursion issues due to folder permissions. So this can be helpful to add:
Code: Select all
set the folder to tFolder
if the folder is tFolder then -- do stuff we expect....
Re: How to list the files inside a folder
Posted: Thu Jan 14, 2016 12:18 pm
by Klaus
Ah, good point, thanks Richard!
Re: How to list the files inside a folder
Posted: Fri Jan 15, 2016 7:02 pm
by jmburnod
Thanks Klaus
If i understand correctly what Richard suggest, this function should be like that :
Code: Select all
function getFilesInFol tFol
put empty into rFilesInFol
if there is a folder tFol then
put the folder into tOldDir
set the folder to tFol
if the folder is tFol then -- do stuff we expect....
put the files into rFilesInFol
filter rFilesInFol without ".*"
set the folder to tOldDir
end if
end if
return rFilesInFol
end getFilesInFol
All the best
Jean-Marc