When I choose the folder "photo",it can open "photo-001.jpg",but can not open the files in "photo1,photo2,photo3"
(see the upload picture)
under is the js
/////////////////////////////////////////////
app.bringToFront();
res ="dialog { \
text:'Open photo',\
group: Group{orientation: 'column',alignChildren:'left',\
photoO:Group{ orientation: 'row', \
b: Button {text:'Photofolder', properties:{name:'open'} ,helpTip:'all photo'},\
s: EditText { text:'', preferredSize: [360, 20] },\
},\
gg: Group{orientation: 'column',alignChildren:'left' },\
timeline:Progressbar{bounds:[0,0,400,10] , minvalue:0,maxvalue:100}\
aa: Button { text:'Open'}, \
}\
}";
win = new Window (res);
var photoOpen=win.group.photoO
photoOpen.b.onClick = function() {
var defaultFolder = photoOpen.s.text;
var testFolder = new Folder(defaultFolder);
if (!testFolder.exists) {
defaultFolder = "~";
}
var selFolder = Folder.selectDialog("Photofolder", defaultFolder);
if ( selFolder != null ) {
photoOpen.s.text = selFolder.fsName;
photoOpen.s.helpTip = selFolder.fsName.toString();
}
}
win.group.aa.onClick=function(){
win.close ()
}
//////////////
win.center();
win.show();
// Use the path to the application and append the samples folder
var samplesFolder = Folder(win.group.photoO.s.text);
//var samplesFolder = Folder("C:/Users/cce/Desktop"+ "/BBB")
//Get all the files in the folder
var fileList = samplesFolder.getFiles()
// open each file
for (var i = 0; i < fileList.length; i++) {
// The fileList is folders and files so open only files
if (fileList instanceof File) {
open(fileList)
}
}
How to open the files in subfolders"photo1,photo2,photo3"
How to open the files in subfolders"photo1,photo2,photo3"
- Attachments
-
- photo1.jpg (68.85 KiB) Viewed 14823 times
Last edited by bamboo on Sun Jul 31, 2016 6:49 am, edited 1 time in total.
Re: How to open the files in "photo1,photo2,photo3"
Replace last linses of your code with the code part I modified.
PS.1 it won't work for subfolders in subfolders
PS.2 it'll stop if the file isn't openable in photoshop
(like Bridge sort or Windows thumbs or else error .tmp etc)
PS.1 it won't work for subfolders in subfolders
PS.2 it'll stop if the file isn't openable in photoshop
(like Bridge sort or Windows thumbs or else error .tmp etc)
Code: Select all
// Get all the files in the folder
var fileList = samplesFolder.getFiles()
// open each file
for (var i = 0; i < fileList.length; i++) {
// The fileList is folders and files so open only files
if (fileList[i] instanceof File) {
open(fileList[i])
}
else if (fileList[i] instanceof Folder) {
var subFoldList = fileList[i].getFiles()
for (var j = 0; j < subFoldList.length; j++) {
if (subFoldList[j] instanceof File) {
open(subFoldList[j])
}
}
}
}
-
- Posts: 29
- Joined: Sat Jul 30, 2016 3:52 am
- Location: San Francisco
Re: How to open the files in "photo1,photo2,photo3"
The getFiles() function only collects files from the specified directory. You will need to use a recursive function to iterate through all the subfolders and retrieve their files.
There's a really nice function in this thread where they do exactly what you need. You can even use a filter to retrieve only the files you need.
https://forums.adobe.com/thread/1246514
There's a really nice function in this thread where they do exactly what you need. You can even use a filter to retrieve only the files you need.
https://forums.adobe.com/thread/1246514
Re: How to open the files in "photo1,photo2,photo3"
Thank you,JavierAroche !!
-
- Posts: 29
- Joined: Sat Jul 30, 2016 3:52 am
- Location: San Francisco
Re: How to open the files in "photo1,photo2,photo3"
I try run this,But cannot open the files in subfolder,why?,I read long time !!
///////////////////////////////////////////////////////////////////////////
var topFolder =Folder('~/desktop/photo');
var fileandfolderAr = scanSubFolders(topFolder,/\.(jpg|tif|psd|bmp|gif|png|)$/i);
var fileList = fileandfolderAr[0];
for(var a = 0 ;a < fileList.length; a++)
{
var docRef = open(fileList[a]);
//do things here
}
function scanSubFolders(tFolder, mask) { // folder object, RegExp or string
var sFolders = new Array();
var allFiles = new Array();
sFolders[0] = tFolder;
for (var j = 0; j < sFolders.length; j++){ // loop through folders
var procFiles = sFolders[j].getFiles();
for (var i=0;i<procFiles.length;i++){ // loop through this folder contents
if (procFiles instanceof File ){
if(mask==undefined) allFiles.push(procFiles);// if no search mask collect all files
if (procFiles.fullName.search(mask) != -1) allFiles.push(procFiles); // otherwise only those that match mask
}else if (procFiles instanceof Folder){
sFolders.push(procFiles);// store the subfolder
scanSubFolders(procFiles, mask);// search the subfolder
}
}
}
return [allFiles,sFolders];
};
///////////////////////////////////////////////////////////////////////////
var topFolder =Folder('~/desktop/photo');
var fileandfolderAr = scanSubFolders(topFolder,/\.(jpg|tif|psd|bmp|gif|png|)$/i);
var fileList = fileandfolderAr[0];
for(var a = 0 ;a < fileList.length; a++)
{
var docRef = open(fileList[a]);
//do things here
}
function scanSubFolders(tFolder, mask) { // folder object, RegExp or string
var sFolders = new Array();
var allFiles = new Array();
sFolders[0] = tFolder;
for (var j = 0; j < sFolders.length; j++){ // loop through folders
var procFiles = sFolders[j].getFiles();
for (var i=0;i<procFiles.length;i++){ // loop through this folder contents
if (procFiles instanceof File ){
if(mask==undefined) allFiles.push(procFiles);// if no search mask collect all files
if (procFiles.fullName.search(mask) != -1) allFiles.push(procFiles); // otherwise only those that match mask
}else if (procFiles instanceof Folder){
sFolders.push(procFiles);// store the subfolder
scanSubFolders(procFiles, mask);// search the subfolder
}
}
}
return [allFiles,sFolders];
};
-
- Posts: 29
- Joined: Sat Jul 30, 2016 3:52 am
- Location: San Francisco
Re: How to open the files in subfolders"photo1,photo2,photo3"
I just tested this code and it works. Double check your path "~/desktop/photo". Does the ~ work as the user path on windows? Try a full absolute path to the folder.
Re: How to open the files in subfolders"photo1,photo2,photo3"
Thank you JavierAroche!!
The code can open only one photo,other cannot be open
like the picture :2.jpg and 3.jpg and the files in subfolder photo1,photo2,photo3 cannot be open
the 1.jpg is opened
I cann't find the cause!!!
The code can open only one photo,other cannot be open
like the picture :2.jpg and 3.jpg and the files in subfolder photo1,photo2,photo3 cannot be open
the 1.jpg is opened
I cann't find the cause!!!
- Attachments
-
- photo2.jpg (78.6 KiB) Viewed 14776 times
Re: How to open the files in subfolders"photo1,photo2,photo3"
Try my solution, it's right under your first post and I tested it, so it works for sure...
Re: How to open the files in subfolders"photo1,photo2,photo3"
Thank you Kukurykus,
All the files can be opened
thanks a lot!!
All the files can be opened
thanks a lot!!