Copy link to clipboard
Copied
Hey there,
i am trying to do a simple folder check.
var folder = new Folder;
folder = folder.selectDlg("Select a folder");
alert( 'isFolder: ' + Folder(folder).exists );
if(folder instanceof Folder || folder == null) {
alert("Please select a folder");
exit();
}
else {
alert("Do something");
}
when i run this i get true even if i have no folder selected. For example if i on my mac go to my Desktop and do not select anything and hit open, it still tells me true.
any ideas?
In that case, try the following
var desktop = new Folder("~/Desktop")
var dest = desktop.selectDlg("Select a folder");
if(dest == null || dest.fsName == desktop.fsName) {
alert("Please select a folder");
}
else {
alert("You selected " + dest.path + "/" + dest.name);
}
In this code, the file browser dialog will always open with the desktop folder. The final selected folder will be in the dest variable, if the user does not select any folder then she will be prompted to select a folder
...Copy link to clipboard
Copied
The reason for this behaviour is that the selectDlg will open the folder chooser window with a folder selected, so even if you don't choose any folder explicitly, the preselected folder is returned. So in your case, the Desktop folder is returned. You need to check if the user cancelled the browser window, in which case the return value would be null. Something like the following should suffice
var folder = new Folder().selectDlg("Select a folder");
if(folder == null) {
alert("Please select a folder");
}
else {
alert("You selected " + folder.path + "/" + folder.name);
}
-Manan
Copy link to clipboard
Copied
hmm that works for the most part. Let me explain the second part. So i have a script that when you select or create a folder, it will then populate the folder with a links folder and copy photos into that links folder. I am building a template flyer design for work. This all works great, but using the code above, if the user doesn't select or create a folder on the desktop, the file will be saved on the desktop and the links folder. I want it nicely packaged into a folder structure of its own. Does this make sense?
Copy link to clipboard
Copied
In that case, try the following
var desktop = new Folder("~/Desktop")
var dest = desktop.selectDlg("Select a folder");
if(dest == null || dest.fsName == desktop.fsName) {
alert("Please select a folder");
}
else {
alert("You selected " + dest.path + "/" + dest.name);
}
In this code, the file browser dialog will always open with the desktop folder. The final selected folder will be in the dest variable, if the user does not select any folder then she will be prompted to select a folder.
-Manan
Copy link to clipboard
Copied
duh! thank you... I was trying to over complicate this thing!!