Sign in to follow this  
Followers 0
dmorand

Read files from sub folders

7 posts in this topic

I have a script I'm working on and I need to read files, but I want to pass the script a starting folder, and then read all the files in that folder, and any sub folder. I'm having problems with how to get to the sub folders properly.

Does anyone have a suggestion?

Share this post


Link to post
Share on other sites



I have a script I'm working on and I need to read files, but I want to pass the script a starting folder, and then read all the files in that folder, and any sub folder. I'm having problems with how to get to the sub folders properly.

Does anyone have a suggestion?

Thanks but doesn't that basically do what _FileListToArray() does?

I can traverse through sub folders, but I can't seem to get back up to the main folder after going through 1 set of sub-folders.

Share this post


Link to post
Share on other sites

Thanks but doesn't that basically do what _FileListToArray() does?

I can traverse through sub folders, but I can't seem to get back up to the main folder after going through 1 set of sub-folders.

I cant' seem to manage the search handles. I need to keep opening new handles when I go into a new folder, but I don't know how to make new variable names.

Share this post


Link to post
Share on other sites

hey i made this recursive function in lua another interpreted scripting language that i use, im not sure if you need to use some of the ocde that it uses but ill post it and an english translation description thingy.

lua code:

file_list = {}
function process_files(path)
    System.currentDirectory(path)
    the_list = System.listDirectory("./")
    for i = 3, #the_list do
        if the_list[i].directory == false then
            file_list[#file_list + 1] = System.currentDirectory() .. "/" .. the_list[i].name
        else
            file_list[#file_list + 1] = System.currentDirectory() .. "/" .. the_list[i].name
            process_files(the_list[i].name)
            the_list = System.listDirectory("./")
        end
    end
    System.currentDirectory("..")
end

english sentance translation:

create file array
start function that is passed one variable a directory path
    set the current directory to the path that the function was passed
    the list of files for the current directory which is also an array
    create a for loop which will loop from file 1 to the last file in the list (it starts at 3 in the above code as . and .. are returned as refresh and return one directory)
        if the file is not a directory then
            set the next item in the overall list to the current path and the file name
        else
            set the next item in the overall list to the current path and the file name (only if you want the folder to be added to the list)
            recursivley call the function and pass it the current file path the folder name
            reset the list of files for the current directory which is also an array as it would have been changed by the recursive function
        end
    end
    exit the directory that was passed
end

i hope you understand that, if you need me to i will direct you to some autoit functions that you may need to use if someone else doesnt before me.


Interpreters have great power!Although they live in the shadow of compiled programming languages an interpreter can do anything that a compiled language can do, you just have to code it right.

Share this post


Link to post
Share on other sites

hey i made this recursive function in lua another interpreted scripting language that i use, im not sure if you need to use some of the ocde that it uses but ill post it and an english translation description thingy.

lua code:

file_list = {}
function process_files(path)
    System.currentDirectory(path)
    the_list = System.listDirectory("./")
    for i = 3, #the_list do
        if the_list[i].directory == false then
            file_list[#file_list + 1] = System.currentDirectory() .. "/" .. the_list[i].name
        else
            file_list[#file_list + 1] = System.currentDirectory() .. "/" .. the_list[i].name
            process_files(the_list[i].name)
            the_list = System.listDirectory("./")
        end
    end
    System.currentDirectory("..")
end

english sentance translation:

create file array
start function that is passed one variable a directory path
    set the current directory to the path that the function was passed
    the list of files for the current directory which is also an array
    create a for loop which will loop from file 1 to the last file in the list (it starts at 3 in the above code as . and .. are returned as refresh and return one directory)
        if the file is not a directory then
            set the next item in the overall list to the current path and the file name
        else
            set the next item in the overall list to the current path and the file name (only if you want the folder to be added to the list)
            recursivley call the function and pass it the current file path the folder name
            reset the list of files for the current directory which is also an array as it would have been changed by the recursive function
        end
    end
    exit the directory that was passed
end

i hope you understand that, if you need me to i will direct you to some autoit functions that you may need to use if someone else doesnt before me.

Thanks a bunch!!! Your logic made perfect sense. I was being an idiot (which I figured) and was trying to assign my search handles to an array when I didn't nead to at all.

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