New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implement file/directory/path listing features #4622

Closed
benfry opened this Issue Aug 17, 2016 · 5 comments

Comments

Projects
None yet
2 participants
@benfry
Member

benfry commented Aug 17, 2016

Moving from the discussion here where @shiffman says:

I think some "file management" features could be useful especially as we think of Processing as a desktop application environment. I have used this example with students who want to bulk load a directory of images or data files. Some possibilities:

  • listFiles(String dir)
  • directoryList(String dir)

It should probably by default use the "sketchPath" (or "dataPath"?) but also allow full paths?

Inside processing.app.Util we have methods to recursively list items in a folder, with options that include whether to just return relative paths (as Strings) or full paths, and to specify an extension being searched for.

Such a menagerie of options! We could also use our funky quoted syntax the way we do with Table and have something like:

  • listFiles(String dir, "directories")
  • listFiles(String dir, "extension=js")
  • listFiles(String dir, "extensions=js,csv,txt")
  • listFiles(String dir, "recursive,extensions=js,csv,txt")
  • listFiles(String dir, "relative,recursive,extensions=js,csv,txt")

In keeping with other API, I'd recommend listPaths() to return a String array (or StringList) and a listFiles() version to return File objects.

@benfry

This comment has been minimized.

Show comment
Hide comment
@benfry

benfry Aug 17, 2016

Member

@shiffman I also totally agree with your point about the desktop environment...

Member

benfry commented Aug 17, 2016

@shiffman I also totally agree with your point about the desktop environment...

@benfry

This comment has been minimized.

Show comment
Hide comment
@benfry

benfry Aug 17, 2016

Member

Another thought is whether we should be handling those comma-separated argument lists via String... which would mean:

listFiles(String dir, "relative", "recursive", "extensions=js|csv|txt");

Also just realizing that extensions can't be a comma-separated list in an already comma-separated list, so the example above uses | instead. We could also just say:

listFiles(String dir, "relative", "recursive", "extension=js", "extension=csv");
Member

benfry commented Aug 17, 2016

Another thought is whether we should be handling those comma-separated argument lists via String... which would mean:

listFiles(String dir, "relative", "recursive", "extensions=js|csv|txt");

Also just realizing that extensions can't be a comma-separated list in an already comma-separated list, so the example above uses | instead. We could also just say:

listFiles(String dir, "relative", "recursive", "extension=js", "extension=csv");
@shiffman

This comment has been minimized.

Show comment
Hide comment
@shiffman

shiffman Aug 18, 2016

Member

I think I like. . .

listFiles(String dir, "relative", "recursive", "extensions=js|csv|txt");

Can "relative" be assumed (unless preceded with / meaning it's a full path)?

Member

shiffman commented Aug 18, 2016

I think I like. . .

listFiles(String dir, "relative", "recursive", "extensions=js|csv|txt");

Can "relative" be assumed (unless preceded with / meaning it's a full path)?

@benfry

This comment has been minimized.

Show comment
Hide comment
@benfry

benfry Aug 18, 2016

Member

Relative should probably be named differently... The idea is that if I say:

String[] paths = listPaths("/Users/shiffman/rainbow/images", "recursive")

that the paths it returns will not all be prefixed with /Users/shiffman/rainbow/images, the Strings returned will be 001.jpg, tortoise.jpg, subfolder/something.jpg, and so on.

When returning File objects, this wouldn't have any impact.

Member

benfry commented Aug 18, 2016

Relative should probably be named differently... The idea is that if I say:

String[] paths = listPaths("/Users/shiffman/rainbow/images", "recursive")

that the paths it returns will not all be prefixed with /Users/shiffman/rainbow/images, the Strings returned will be 001.jpg, tortoise.jpg, subfolder/something.jpg, and so on.

When returning File objects, this wouldn't have any impact.

@benfry benfry closed this in dc36abb Nov 15, 2016

@benfry

This comment has been minimized.

Show comment
Hide comment
@benfry

benfry Nov 15, 2016

Member

Added for what will likely be Processing 3.3 (if not 3.2.4).

Member

benfry commented Nov 15, 2016

Added for what will likely be Processing 3.3 (if not 3.2.4).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment