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

Create folder from filename

New Here ,
Jun 09, 2009 Jun 09, 2009

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
1.7K
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

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(

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

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

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

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

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

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?

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

    }

   }

};

main();

Something like that should work.

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

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

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