Skip to main content
Participant
June 9, 2009
Answered

Create folder from filename

  • June 9, 2009
  • 1 reply
  • 1761 views

Hi

I need a script that move files to a folder with the same name as the first 8 characters of the file name, that has to be moved. If the folder doesn't exist, it has to be created. I'm new in Javascript! Can anybody help me??

thanx

This topic has been closed for replies.
Correct answer xbytor2

Hi Michael

This is very close, but I need to pick up every file in a specific folder (hotfolder), not just one file. Is this posible?


function createFolder(file) {

  var parentFolder = file.parent;
  var saveFolder = new Folder( parentFolder + '/' + file.name.substring( 0, 8 ) );
  if( !saveFolder.exists ) saveFolder.create();
  var saveFile = new File( saveFolder + '/' + file.name);
  if( file.copy( saveFile ) ) file.remove();
}

function main() {

   var folder = new Folder("~/Desktop/images");

   var files = folder.getFiles();

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

     var f = files;

     if (f instanceof File) {

      createFolder(f);

    }

   }

};

main();

Something like that should work.

1 reply

Inspiring
June 9, 2009

Need more details. Where are the files now? Where do you want the new folder? etc

MannendkAuthor
Participant
June 9, 2009

The files are placed in a folder by a workflow. The new folder can be a subfolder to the workflow output folder, where the files where picked up. But that's not the major issue, I can change the path, if it is needed.

Inspiring
June 9, 2009

var file = new File( '/c/temp4/SLIP762011.jpg' );
var parentFolder = file.parent;
var saveFolder = new Folder( parentFolder + '/' + file.name.substring( 0, 8 ) );
if( !saveFolder.exists ) saveFolder.create();
var saveFile = new File( saveFolder + '/' + file.name);
if( file.copy( saveFile ) ) file.remove();