Chrisir
August 30, 2019, 12:27pm
#1
Hello all,
I‘d like to tell selectInput() which folder and file extension to use:
File file1= new File( sketchPath(”“) + ”*.txt“);
selectInput(”...“, ”...“, file1);
Doesn’t work. It starts with the Desktop Folder instead (and not in sketch path folder).
(Sorry for the wrong „“, my iPhone…)
What do I have to change?
Win 10.
Thank you!
Chrisir
1 Like
Limited research but probly these next links could help:
Kf
3 Likes
Actually
selectInput
(
"Select a file to process:"
,
"fileSelected"
, dataFile(
"*.txt"
));
did the trick.
Remaining problem is that the load dialog is not in the foreground in Win 10 but hidden.
Any ideas?
2 Likes
This sounds like a bug worth reporting. Is that behind a PDE sketch window, or is it from an exported application?
1 Like
kll
September 1, 2019, 1:00am
#5
in Win 10 / processing 3.5.3. /
called from a keyPressed()
no problem
but yes usually thing like
JOptionPane.showInputDialog
tend to be behind the canvas window GRRR
different example:
// https://discourse.processing.org/t/file-listing-order/7148/23
// https://discourse.processing.org/t/selectinput-i-like-to-tell-it-the-folder-to-use/13703/3
// as started from load display image i have a sub dir /data/ with a data\moonwalk.jpg
static final String PICS_EXTS = "extensions=,png,jpg,jpeg,gif,tif,tiff,tga,bmp,wbmp";
File dir;
String[] imagePaths = {};
int imagesFound = 0;
boolean havefile = false;
PImage img;
void filedata() { // @GoToLoop
dir = dataFile("");
println(dir);
if (dir.isDirectory()) {
imagePaths = listPaths(dir.getPath(), "files", "recursive", PICS_EXTS);
imagesFound = imagePaths.length;
}
printArray(imagePaths);
println("Found", imagesFound, "image(s)");
}
void setup() {
size(300,300);
filedata();
println("use: key [r] for file open dlg\n or key [0 (...x]) for load from array");
}
void draw() {
if ( havefile ) image(img,0,0); //,width,height
}
void keyPressed() {
if ( key == 'r') {
selectInput("open picture: ", "fileSelected", dataFile(PICS_EXTS));
}
if ( key == '0') {
String thefile = imagePaths[0];
println("you selected: key ["+key+"] "+thefile);
img = loadImage(thefile);
havefile = true;
}
}
void fileSelected(final File sel) {
if (sel != null) {
String thefile = sel.getPath();
println("you selected: "+thefile);
img = loadImage(thefile);
havefile = true;
}
}
1 Like
Chrisir
September 20, 2019, 3:03pm
#7
I have to say, sometimes it works. It seems to store the last directory implicitly. So often it looks like it works but it doesn’t.
It doesn’t really take the directory from the file I give to selectInput(). Seems to be a bug.
This is the core line for me :
selectInput("open picture: ", "fileSelected", dataFile(PICS_EXTS));
I understand this line:
static final String PICS_EXTS = "extensions=,png,jpg,jpeg,gif,tif,tiff,tga,bmp,wbmp";
How would I tell it the folder as well?
Thanks!
Chrisir