I just noticed there is no way to read Directory in such a way that it would return a table of all the files.
Main point here being consistency with DropFile option. As if I drop more than one file to a window, it will give me a table containing every files path and type.
Based upon this I made a system where it adds all those files to my window when dropfiled, but problem is now that I also planned that if there is folder, that it would also add all the contents of the folders and subfolders, and I meant to simply have AddFilesToDirectory(Dir, T_Files), and then I meant that if it encounters a directory, it would simply call itself again, as in, recursive function.
However, since DropFiles and all Directory accessing functions have different logic into them, now I either have to make two different functions, or I have to prepare the directory myself to make it into similar table as Dropfile does.
Wishlist: t = GetDirectoryAsTable(path)
Re: Wishlist: t = GetDirectoryAsTable(path)
whats the diffirence out of p_TraverseDir() example in DirectoryItems() ?
Christos
Re: Wishlist: t = GetDirectoryAsTable(path)
Just couple of lines from the whole:
Using DirectoryItems(File) wouldn't work in this example.
I already made a function which actually uses the directory items and makes it into a table and returns it to be used instead of DirectoryItems(File).
But so the main point is not that it is difficult to replace or something, but that DirectoryItem isn't compatible with DropFiles action, but they need to be handled differently.
Code: Select all
Window.DropFileToAWindow(WindowID, Action)
Project.AddFilesToDirectory(DirItem, Action.DropFiles, DirShowing)
...
Function Project.AddFilesToDirectory(DirItem, T_Files, Path)
For Local n = 0 To TableItems(T_Files)-1
Local File = T_Files[n]
Local t = GetFileAttributes(File)
If t.type = #DOSTYPE_DIRECTORY
Project.AddFilesToDirectory(NewDirItem, DirectoryItems(File), newpath)
I already made a function which actually uses the directory items and makes it into a table and returns it to be used instead of DirectoryItems(File).
But so the main point is not that it is difficult to replace or something, but that DirectoryItem isn't compatible with DropFiles action, but they need to be handled differently.
- airsoftsoftwair
- Posts: 5668
- Joined: Fri Feb 12, 2010 2:33 pm
- Location: Germany
- Contact:
Re: Wishlist: t = GetDirectoryAsTable(path)
Sounds like a job for ReadDirectory()?
Re: Wishlist: t = GetDirectoryAsTable(path)
Thanks. Looks like that solves the problem.
Seems I misunderstood that command when I read the description. Thought it was going to be returning a string with all files separated, which sounded odd. Missed that it actually said string ARRAYS, meaning tables.
Seems I misunderstood that command when I read the description. Thought it was going to be returning a string with all files separated, which sounded odd. Missed that it actually said string ARRAYS, meaning tables.
- airsoftsoftwair
- Posts: 5668
- Joined: Fri Feb 12, 2010 2:33 pm
- Location: Germany
- Contact:
Re: Wishlist: t = GetDirectoryAsTable(path)
Yeah, that's because ReadDirectory() is an ancient function. It has been there since the ancient Hollywood 1.0 which didn't use the Lua VM but a custom interpreter which didn't have any support for tables but just for arrays. You can also see that it's an ancient function in the fact that you have to pass tables that will be filled by ReadDirectory(). That's a thing that's also no longer done in Hollywood >= 2.0. Newer Hollywood functions would typically just return the tables to you but Hollywood 1.x wasn't capable of doing that.