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

A script to batch rename files, create corresponding folders, move files, create zip files?

Participant ,
Sep 28, 2023 Sep 28, 2023

I want to run script to batch rename images in a folder that I have placed png files into, then batch create sub-folders based on each individual image’s new name into a different folder. Lastly, I would like to move the png image, and also create a zip file of each individual image and save in its corresponding sub-folder.

 

Specifically, I have 2 existing folders on my Mac desktop “For Processing” and “Processing Completed”. In the “For Processing” folder, I will add any number of png images that I have created with various filenames. When it comes time that I need to process, I rename the png images to a more meaningful and consistent naming convention eg. Map-001.png, Map-002.png, etc. Then in the different folder “Processing Completed”, I create sub-folders for each image, eg sub-folder named Map-001, the next Map-002, etc. Inside each of these sub-folders I then move the png file, as well as save a corresponding zip file, ie. “Map-001.png” and “Map-001.zip” go inside the Map-001 sub-folder.

TOPICS
Actions and scripting , macOS
1.4K
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
Adobe
Community Expert ,
Sep 28, 2023 Sep 28, 2023

Where are you stuck in creating your script?

 

As you are on a Mac and this is all Finder-level stuff, you could do it with AppleScript without even worrying about having any interaction from Adobe apps.

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
Participant ,
Sep 28, 2023 Sep 28, 2023

I have never usedAppleScript - I'll need to learn 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
Community Expert ,
Sep 29, 2023 Sep 29, 2023
quote

I have never usedAppleScript - I'll need to learn it ...


By CatoPbx


OK I understand, but ExtendScript can only do so much... I believe you're going to have to make a system call to .zip the files. The rest could be done by using a script triggered from an Adobe app.

 

Where are you stuck in creating your script in ExtendScript/JavaScript?

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
Participant ,
Sep 29, 2023 Sep 29, 2023
I've only done the creation of new folders - scratching my head trying to work out how to zip files, and also move the originals.
Excuse my over-commenting - I do it so I can follow stuff when I can't think anymore ...

 

main();

function main(){

    // The folder locations of 2 main folders (change as necessary)
    var processingInFolder = Folder('~/Desktop/PROCESSING-IN');
    var processingOutFolder = Folder('~/Desktop/PROCESSING-OUT');

    // If there are files in the Processing-In folder,
    // create an array of files contained in that folder
	if (processingInFolder == null) return;
	var fileList = processingInFolder.getFiles();

	// Create sub-folders under the Processing-Out folder, based on the filenames
    // in the Processing-In folder without the file extensions

    if (processingOutFolder == null) return;
    
    var theFilenamePrefix;
    var nextFolder; 

    // Iterate over each of the files
    for (var i=0; i<fileList.length; i++) { 

        // Get the filename prefix without the extension
        theFilenamePrefix = fileList[i].name.replace(/\.[^\.]+$/, '');
 
        // Create the sub-folder in the Processing-Out folder
        nextFolder = new Folder(processingOutFolder + '/' + theFilenamePrefix); 
        if(!nextFolder.exists) {nextFolder.create() }; 
    } 

}

 

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 ,
Sep 29, 2023 Sep 29, 2023

If I remember correctly, you can copy/rename in a single step, but you then need to permanently delete the originals as there is no move file system command in ES/JS.

 

EDIT: Here is a very basic example:

 

var origDoc = File("~/Desktop/For Processing/inputFile.png");
var copyRenameDoc = File("~/Desktop/Processing Completed/outputFile.png");
File(origDoc).copy(copyRenameDoc);
origDoc.remove();

 

Personally, I think this is best done using other methods (AppleScript, Unix system script, ExifTool (Perl), Python or even Powershell for Mac).

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
Participant ,
Sep 29, 2023 Sep 29, 2023

OK, what one method as an experienced coder would you use - in your opinion/preference? Also some coding clues in the right direction would help me, as someone quite inexperienced.

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 ,
Sep 29, 2023 Sep 29, 2023

I'm not an experienced coder, I just learn things as needed.

 

JavaScript will mostly get you there, but you are still going to need to find out how to run a system-level script from the JS to ZIP the files. Apart from that, you can probably do everything else, but you still need to execute the script from an Adobe app or Visual Studio Code debugger etc.

 

I'd probably scour the web for AppleScript, and even then, it may still need to make a system call or two, I don't know.

 

ExifTool is going to be pretty easy for the most part (but the syntax is always fun, but there is a great support forum), but again, you will need to patch on a step for the ZIP creation.

 

Python is a good choice, you may even be able to get ChatGPT to write the script for you... And it might even work! 

 

I don't have a silver bullet for you.

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
Participant ,
Sep 29, 2023 Sep 29, 2023

I used the mac Archive Utility as per advice on this link: https://apple.stackexchange.com/questions/225241/batch-compress-multiple-folders-into-individual-zip... and found I was able to do the following as per the author, ababak's advice, which allows me to drop individual images onto the Archive Utility icon and hooray - it made each of them a separate zip file. 

"There's an alternative solution that's built-in if you don't want to use Automator and are fine with changing Archive Utility's settings.

  1. Open the Archive Utility.app located in /System/Library/CoreServices/Applications/
  2. Go to File > Preferences
  3. Change the "Use Archive Format" preference to "Zip archive"
  4. Drag and drop the folders into its icon in the dock."

 

Now the next challenges:

  • I don't now if it'd be possible to do the equivalent of dropping the images into the Archive Utility icon but call from within a script?
  •  The zipped files are all saved like this: "Map-01.png.zip" with the .png in the filename which is normal when zipping just individual files, but it means I have to change the name of all of the zipped files, and still move each one to their corresponding sub-folder under the "Processing-Out" 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
Participant ,
Oct 01, 2023 Oct 01, 2023
LATEST

Just letting you know that rather than using a Photoshop script, I ended up using JavaScript (node.js) to process those files. The script renames the zip files correctly, creates sub-folders in the "Out" folder based on the image names without the extension, and moves all files from the "In" folder (png and zip files) to their respective sub-folders in the "Out" 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