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

Create folder from filename

New Here ,
Jun 09, 2009 Jun 09, 2009

Copy link to clipboard

Copied

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

TOPICS
Actions and scripting

Views

1.6K

Translate

Translate

Report

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

Advisor , Jun 09, 2009 Jun 09, 2009

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(

...

Votes

Translate

Translate
Adobe
Guru ,
Jun 09, 2009 Jun 09, 2009

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

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 ,
Jun 09, 2009 Jun 09, 2009

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

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
Guru ,
Jun 09, 2009 Jun 09, 2009

Copy link to clipboard

Copied

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();

Votes

Translate

Translate

Report

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 ,
Jun 09, 2009 Jun 09, 2009

Copy link to clipboard

Copied

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?

Votes

Translate

Translate

Report

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
Advisor ,
Jun 09, 2009 Jun 09, 2009

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

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 ,
Jun 09, 2009 Jun 09, 2009

Copy link to clipboard

Copied

LATEST

This couldn't been any better, a lot of thanks from here.

Votes

Translate

Translate

Report

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