Wishlist: t = GetDirectoryAsTable(path)

Feature requests for future versions of Hollywood can be voiced here
Post Reply
Bugala
Posts: 1329
Joined: Sun Feb 14, 2010 7:11 pm

Wishlist: t = GetDirectoryAsTable(path)

Post by Bugala »

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.
plouf
Posts: 613
Joined: Sun Feb 04, 2018 11:51 pm
Location: Athens,Greece

Re: Wishlist: t = GetDirectoryAsTable(path)

Post by plouf »

whats the diffirence out of p_TraverseDir() example in DirectoryItems() ?
Christos
Bugala
Posts: 1329
Joined: Sun Feb 14, 2010 7:11 pm

Re: Wishlist: t = GetDirectoryAsTable(path)

Post by Bugala »

Just couple of lines from the whole:

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)
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.
User avatar
airsoftsoftwair
Posts: 5668
Joined: Fri Feb 12, 2010 2:33 pm
Location: Germany
Contact:

Re: Wishlist: t = GetDirectoryAsTable(path)

Post by airsoftsoftwair »

Bugala wrote: Thu Feb 13, 2025 1:00 pm I just noticed there is no way to read Directory in such a way that it would return a table of all the files.
Sounds like a job for ReadDirectory()?
Bugala
Posts: 1329
Joined: Sun Feb 14, 2010 7:11 pm

Re: Wishlist: t = GetDirectoryAsTable(path)

Post by Bugala »

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.
User avatar
airsoftsoftwair
Posts: 5668
Joined: Fri Feb 12, 2010 2:33 pm
Location: Germany
Contact:

Re: Wishlist: t = GetDirectoryAsTable(path)

Post by airsoftsoftwair »

Bugala wrote: Sat Mar 01, 2025 8:29 am 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.
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.
Post Reply