Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
1

Create folder and move files by reading csv

Explorer ,
Nov 11, 2015 Nov 11, 2015

Hello Guys,

Is that possible create a script to read csv and create folders and move the files into the folder.

My csv will look like

Screen Shot 2015-11-11 at 5.25.29 PM.png

It has folder names and File names, I have kept my files (Mention in "File names" column) in desktop. When I run the script it need to read the csv and create folder(as per "Folder Names") and the correct file need to move into particular folder. Hope I made the requirements clear.

So from the above csv we need 4 folders and the respective files need to move into their folders. Looking for help!!!

TOPICS
Actions and scripting
2.6K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Guide , Nov 13, 2015 Nov 13, 2015

Thing may have changed as I tested it with CS6.

Please try this then.

#target photoshop;

main();

function main(){

var csv = File.openDialog("Please select CSV file.","CSV File:*.csv");

if(csv == null) return;

var sourceFolder = Folder.selectDialog( "Please select source folder");

if(sourceFolder == null) return;

var data=[];

csv.open('r');

while(!csv.eof){  

var InputLine = csv.readln();

if(InputLine.length > 3) data.push(InputLine);

}

csv.close();

for(var f in data){

var dataLine = data.split

...
Translate
Adobe
Community Expert ,
Nov 11, 2015 Nov 11, 2015

Would not even need Photoshop you can just use javascript.  That would not require any Photoshop function.  Also Adobe Photoshop uses it own version of javascript.  I do not see file.move() listed in Adobe object viewer so it may not be supported by Adobe scripting.  I have never seen a Photoshop that used file.move(). So you may need to use File.Copy() and File.remove() in a Photoshop Script that may change the file creation date.

FileSystemObject.CreateFolder() : FileSystemObject « MS JScript « JavaScript Tutorial

File.Move() : File « MS JScript « JavaScript Tutorial

Capture.jpg

JJMack
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Nov 13, 2015 Nov 13, 2015

Hello JJ,


Thank you for you time.Yes it can be worked without PS using jsx, but I have also included some task in PS. So I have planned to link this requested script along with my work so once the work is completed it will read the csv and the files get moved into respective folder.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Nov 12, 2015 Nov 12, 2015

May be you can use applescript to read CSV and use the move command to move files from present folder to folder mentioned in CSV. You may need to add 'fixed path of present and destination drives' before giving move command. If you are not on MAC only option is javascript (but there's no move command) as suggested by JJ

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Nov 13, 2015 Nov 13, 2015

There is a move command, but you need to use Bridge.

An example:-

#target bridge

var outputFolder = Folder("/c/output/folder");

if(!outputFolder.exists) outputFolder.create();

app.document.thumbnail = Folder("/c/source/folder");

app.document.deselectAll();

//Get a list of all tif,jpg and cr2 files

var filestomove = app.document.getSelection("tif,jpg,cr2");

//move the files

for(var z in filestomove){

new Thumbnail(filestomove).moveTo(outputFolder);

}

Also File.rename(); works well as a move command.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Nov 13, 2015 Nov 13, 2015

Merlin,

Thanks for looking int this.

I have a jsx which can move files from 1 folder to another without using bridge, but here my requirement is bit different which need to read the csv and create folders and move the respective files into respective folders.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Nov 13, 2015 Nov 13, 2015

var sourceFolder = new Folder("~/Desktop/LNW/LNW Working Folder"); 

var destFolder = new Folder("~/Desktop/LNW/LNW Backup"); 

var fileList = sourceFolder.getFiles(); 

for (var i = 0; i < fileList.length; i++) { 

    if (fileList.copy(decodeURI(destFolder) + "/" + fileList.displayName)) { 

        fileList.remove(); 

    }   

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Nov 13, 2015 Nov 13, 2015

Hi Bala,

Do you have any link to refer applescript for reading csv and move files.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Nov 13, 2015 Nov 13, 2015

Try this

#target photoshop;

main();

function main(){

var csv = File.openDialog("Please select CSV file.","CSV File:*.csv");

if(csv == null) return;

var sourceFolder = Folder.selectDialog( "Please select source folder");

if(sourceFolder == null) return;

var data=[];

csv.open('r');

while(!csv.eof){  

var InputLine = csv.readln();

if(InputLine.length > 3) data.push(InputLine);

}

csv.close();

for(var f in data){

var dataLine = data.split(',');

var folderName = dataLine[0].toString().replace(/^\s+|\s+$/g,'');

var fileName = dataLine[1].toString().replace(/^\s+|\s+$/g,'');

var file = File(sourceFolder + "/" + fileName);

if(!file.exists) continue;

var outputFolder = Folder(sourceFolder + "/" + folderName);

if(!outputFolder.exists) outputFolder.create();

file.rename(File(outputFolder + "/" + fileName));

    }

alert("All Completed");

};

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Nov 13, 2015 Nov 13, 2015

Will give a try, Thanks!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Nov 13, 2015 Nov 13, 2015

Merlin,

The jsx creating folder as expected, but not moving the files into the folders.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Nov 13, 2015 Nov 13, 2015

Thing may have changed as I tested it with CS6.

Please try this then.

#target photoshop;

main();

function main(){

var csv = File.openDialog("Please select CSV file.","CSV File:*.csv");

if(csv == null) return;

var sourceFolder = Folder.selectDialog( "Please select source folder");

if(sourceFolder == null) return;

var data=[];

csv.open('r');

while(!csv.eof){  

var InputLine = csv.readln();

if(InputLine.length > 3) data.push(InputLine);

}

csv.close();

for(var f in data){

var dataLine = data.split(',');

var folderName = dataLine[0].toString().replace(/^\s+|\s+$/g,'');

var fileName = dataLine[1].toString().replace(/^\s+|\s+$/g,'');

var file = File(sourceFolder + "/" + fileName);

if(!file.exists) continue;

var outputFolder = Folder(sourceFolder + "/" + folderName);

if(!outputFolder.exists) outputFolder.create();

if(file.copy(outputFolder + "/" + fileName)) file.remove();

    }

alert("All Completed");

};

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Nov 13, 2015 Nov 13, 2015

Just a thought are your files read only? as this would stop them from being moved.

If the second script copies the files but leaves the originals then you will have read only files.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Nov 13, 2015 Nov 13, 2015

But the second scripts move/copies the files, the original is deleted in my machine.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 13, 2015 Nov 13, 2015

Move moves file from one place to the other. If on the same disk its a move of the directory entries from one directory to the other the files are not actually moved or written.  If the move is to a different disk the files are copied from one disk to the other then the orginal files are deleted.

If you want two files that is a copy operation not a move operation.

JJMack
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Nov 13, 2015 Nov 13, 2015
LATEST

Thanks JJ, got it

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Nov 13, 2015 Nov 13, 2015

Thanks a lot!!! its working as expected

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines