Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!
# Pops up a dialog box letting the user select a folder
answer folder "Vælg mappe"
# Set the default folder to the folder selected by the user
# (this is stored in the 'it' variable
set the defaultfolder to it
put the files into field "FileList"
# Filter the lines in the list of all the files
filter lines of field "FileList" with regex pattern "(?i)\.(ft|html)$"
If I want to show the folder and a slash on the files in a subfolder, how to do this?
Brg Tue.
Last edited by tusa on Tue Oct 24, 2017 10:38 pm, edited 1 time in total.
sincde version 8 (or maybe since version 7?) you do not need to set "the defaultfolder" anymore!
This will do:
...
answer folder "Vælg mappe"
put files(it) into field "FileList"
...
But I do not understand your actual question?
If I want to show the folder and a slash on the files in a subfolder,
Right now my List i showing all files like this:
file_1.ft
file_2.ft
file_3.ft
file_in_subfolder_2.ft
file_in_subfolder_2.ft
file_in_subfolder_2.ft
I wan't it to show this:
file_1.ft
file_2.ft
file_3.ft
subfolder/file_in_subfolder_2.ft
subfolder/file_in_subfolder_2.ft
subfolder/file_in_subfolder_2.ft
on mouseUp
answer folder "Vælg mappe"
## ALWAYS check if user cklicked CANCEL!!
if it = EMPTY then
exit mouseup
end if
## Only use IT once, since IT will change when you least exspect IT :-)
put it into tMainFolder
## Now first collect all data before putting them into a field
put files(tMainFolder) into tMainFiles
put folders(tMainFolder) into tFolders
## Loop through all subfolders
repeat for each line tFolder in tFolders
put files (tMainFolder & "/" & tFolder) into tFiles
## Now loop through all files and create your pathname
repeat for each line tFile in tFiles
put tFolder & "/" & tFile & CR after tMainFiles
end repeat
end repeat
## Get rid of last CR
delete char -1 of tMainFiles
put tMainFiles into field "FileList"
end mouseUp
on getMyFiles
answer folder "Select a folder"
if it = empty then exit getMyFiles
put empty into rMyFiles
put it into tPathFol
put LesFilesInFol(tPathFol) into tAllFiles
put LesFolInFol(tPathFol) into tAllSubFol
repeat for each line tOneFile in tAllFiles
put tPathFol & "/" & tOneFile & cr after rMyFiles
end repeat
repeat for each line tOneFol in tAllSubFol
put tPathFol & "/" & tAllSubFol into tPathFol
put LesFilesInFol(tPathFol) into tAllFiles
repeat for each line tOneFile in tAllFiles
put tPathFol & "/" & tOneFile & cr after rMyFiles
end repeat
end repeat
put rMyFiles
end getMyFiles
--•• -- folders in a folder
function LesFolInFol tFol
put empty into rLesFol
put the defaultFolder into tOldDF
set the defaultFolder to tFol
put the folders into rLesFol
set the defaultFolder to tOldDF
filter rLesFol without ".*"
return rLesFol
end LesFolInFol
function LesFilesInFol tFol -- files in a folder without ".*"
put empty into rLesFilesInFol
if there is a folder tFol then
put the defaultFolder into tOldDF
set the defaultFolder to tFol
put the files into rLesFilesInFol
set the defaultFolder to tOldDF
filter rLesFilesInFol without ".*"
end if
return rLesFilesInFol
end LesFilesInFol
# Pops up a dialog box letting the user select a folder
answer folder "Vælg mappe"
## Check if user cklicked CANCEL!!
if it = EMPTY then
exit menuPick
end if
# Set the default folder to the folder selected by the user
# (this is stored in the 'it' variable
put it into tMainFolder
## Now first collect all data before putting them into a field
put files(tMainFolder) into tMainFiles
put folders(tMainFolder) into tMainFolders
## Loop through all subfolders
repeat for each line tFolder in tMainFolders
put files (tMainFolder & "/" & tFolder) into tFiles
## Now loop through all files and create your pathname
repeat for each line tFile in tFiles
put tFolder & "/" & tFile & CR after tMainFiles
end repeat
end repeat
put tMainFiles into field "FileList"
# Filter the lines in the list of all the files
filter lines of field "FileList" with regex pattern "(?i)\.(ft|html)$"
Now I just need to filter the files and then I want to remove the file extensions, on the files I show in the list
The filter part is working now, I only show .ft and .html files, but still missing the last part with the extensions.
function walkDir dirPath
-- This recursive function expects a folder path.
-- It returns a file list for that folder and for each
-- sub-folder it contains (pre-order search)
-- Invisible files are excluded.
-- David Vaughan's version; accounts for directory permissions
if dirPath contains "//Network" then
-- avoids specific case of alias looping; other aliases handled okay below
return empty
end if
put empty into tList
set defaultFolder to dirPath
-- Dar's discovery. Check permissions were ok
get the Result
if it is not empty then
-- subtract 1 from isDepth
return empty
end if
put the long files into fList
repeat for each line fLine in fList
if char 1 of fLine <> "." then
put item 1 of fLine & comma & last item of fLine into fData
put dirPath & "/" & fData & return after tList
end if
end repeat
get the folders
repeat for each line x in it
if char 1 of x <> "." then
put walkDir(dirPath & "/" & x) after tList
end if
end repeat
-- subtract 1 from isDepth
return tList
end walkDir
on mouseUp
put empty into field "result"
answer folder "Pick a folder you want to walk:"
if it is empty then exit mouseUp
if last char of it <> "/" then put "/" after it
put walkDir(it) into field "result"
end mouseUp
function walkDir dirPath
set the directory to dirPath
return shell("ls -R")
end walkDir
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com