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

Save in directory based on filename.

New Here ,
Jan 24, 2017 Jan 24, 2017

Copy link to clipboard

Copied

I am very new to scripting.  I am looking to create a script that will save a .tif file with LZW compression to a file in a directory based on the current image filename.  If that directory doesn't exist it will create it.  All of my filenames are based on a 7 digit system. 

For example... I want to take file name  "123-456_A"  and put it in the following folder system...

Product(Starting folder on the server)
-1
--12
---123
----123-
-----123-4
------123-45
-------123-456(Final Folder)

The "_A" etc will be ignored. Is this possible? 

TOPICS
Actions and scripting

Views

997

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

Community Expert , Jan 25, 2017 Jan 25, 2017

kareyh56356757​,

a folder hierarchy like yours doesn't make any sense for me, sorry. But anyway, try this:

// folder_saveTif_inFolderBasedOnFilename.jsx

// https://forums.adobe.com/thread/2268221

// regards pixxxel schubser

// only file names eg 123-456_A or 100-123_Z allowed

var aDoc = activeDocument, nme = aDoc.name.replace(/\.[^\.]+$/,""), reg = /^\d{3}-\d{3}_./, tmp = nme.split("");

checkAndSave();

function checkAndSave() {

    if( reg.test( nme ) == false) {

        alert ("wrong file name"); return;

...

Votes

Translate

Translate
Adobe
Community Expert ,
Jan 25, 2017 Jan 25, 2017

Copy link to clipboard

Copied

Please post screenshots illustrating the task and Folder structure better.

And please explain what exactly you mean by

save a .tif file with LZW compression

Save a copy of the active File? Save the active File as a new file?

With Layers or flattened?

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 ,
Jan 25, 2017 Jan 25, 2017

Copy link to clipboard

Copied

Screen Shot 2017-01-25 at 7.09.24 AM.png
Would be saving the active file as a new file with the following TIF options.

Screen Shot 2017-01-25 at 7.11.36 AM.png

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
Community Expert ,
Jan 25, 2017 Jan 25, 2017

Copy link to clipboard

Copied

kareyh56356757​,

a folder hierarchy like yours doesn't make any sense for me, sorry. But anyway, try this:

// folder_saveTif_inFolderBasedOnFilename.jsx

// https://forums.adobe.com/thread/2268221

// regards pixxxel schubser

// only file names eg 123-456_A or 100-123_Z allowed

var aDoc = activeDocument, nme = aDoc.name.replace(/\.[^\.]+$/,""), reg = /^\d{3}-\d{3}_./, tmp = nme.split("");

checkAndSave();

function checkAndSave() {

    if( reg.test( nme ) == false) {

        alert ("wrong file name"); return; }

    else { tmp.splice(3,1); tmp.splice(-2); tmp[2] += "-";

        for( i = 1; i < 6; i++ ) { tmp = tmp[i-1] + tmp; };

        var saveFol = Folder ("~/Desktop");

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

            saveFol = Folder( saveFol + "/" + tmp );

            if (!saveFol.exists) { saveFol.create() };

        };

    var saveName = "/" + nme + ".tif";

    var saveFile = new File( saveFol + saveName );

    if( saveFile.exists ) { alert( saveFile + "\nFile already exists - not saved now" ); return; };

    saveAsTIFF( saveFile ); alert( saveFol + saveName + " saved" )

    //aDoc.close( SaveOptions.DONOTSAVECHANGES );

    }; return;

};

function saveAsTIFF( saveFile ) {

    tiffSaveOptions = new TiffSaveOptions();

    tiffSaveOptions.layers = true;

    tiffSaveOptions.imageCompression = TIFFEncoding.TIFFLZW;

    activeDocument.saveAs( saveFile, tiffSaveOptions, false );

}

This snippet should create the wished folder hierarchy (on your desktop) based on the given example file name.

Have fun

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 ,
Jan 26, 2017 Jan 26, 2017

Copy link to clipboard

Copied

I didn't design the folder system.... I just have to use it   Is there anyway I can set an absolute path(?) that points to a location on a sever verses the desktop? I am on a Mac and tried putting in the path but it just returns and error.

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 ,
Jan 26, 2017 Jan 26, 2017

Copy link to clipboard

Copied

I should add that it is an smb:// path

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
Community Expert ,
Jan 26, 2017 Jan 26, 2017

Copy link to clipboard

Copied

kareyh56356757​,

what is the problem?

At first: I'm not really familiar with Mac OS and server paths.

Do you have a screenshot of the part of your desktop which shows your server icon?

Eg the name of the icon is "Transfer". Maybe this name is different to the real name of the server (eg sxyztech)

One possible way to find the path is: open a file which is located directly on Transfer/yourExampleFile.psd

Run this line of code:

alert(activeDocument.path)

On your Mac you should get now a result like this:

/Transfer/yourExampleFile.psd

And now you can try to replace this line of my code:

var saveFol = Folder ("~/Desktop");

with this:

var saveFol = Folder ("/Transfer");

Perhaps this helps you to find your way.

Have fun

And give a feedback please. I'm very interested for your answer.

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 ,
Jan 26, 2017 Jan 26, 2017

Copy link to clipboard

Copied

That worked great to find the correct path.  Thank you!  One thing that I have noticed is that it is creating the "100-" folder in the wrong place.   This is so close and I am very grateful! 

Screen Shot 2017-01-26 at 2.25.18 PM.png
It should show up as the highlighted folder above but instead it is showing as "100-"  where it should be "100".

To add complication, my predecessor deviated from the folder system in spots.  In the example below the "203-" folder was skipped and went directly into the "203-X" numbering. 
Screen Shot 2017-01-26 at 2.28.08 PM.png

Because all of these files are linked to another program I can't change the existing structure.  I can make sure it is correct going forward but not anything that is already there.  Is there anyway to include an "If" or "else" to take this into account?  I realize this is asking a lot and I may have to manual correct these items. 

Thank you so much for your help so far!  This has been the absolute closest I have come to making his script a reality after lots of trial and error.

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
Community Expert ,
Jan 26, 2017 Jan 26, 2017

Copy link to clipboard

Copied

The first one is easy.

Replace line #12 and #13 in my code with:

    else { tmp.splice(-2); //tmp.splice(3,1); tmp.splice(-2); tmp[2] += "-";

        for( i = 1; i < 7; i++ ) { tmp = tmp[i-1] + tmp; };

Have fun

The second part is more complex. Sorry but I don't want spend time for check this now.

Furthermore it is another question.

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 ,
Jan 27, 2017 Jan 27, 2017

Copy link to clipboard

Copied

Thank you for all of your help!  It is very appreciated!!!

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

Copy link to clipboard

Copied

This script has been working perfect for me!  Is there a way to alter it for files that have a naming structure of ZZ12345_A ?  Basically I want it to read any 7 digit filename and put it in the coordinating folder. 

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
Community Expert ,
Jun 09, 2017 Jun 09, 2017

Copy link to clipboard

Copied

Hi kareyh56356757​,

hmmh?

ZZ12345_A is not a 7 digit filename.

Furthermore:

which letters and/or digits in the filename are fix and which ones are variable?

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

Copy link to clipboard

Copied

I realized my mistake and fixed it with the following...

var aDoc = activeDocument, nme = aDoc.name.replace(/\.[^\.]+$/,""), reg = /^\w{2}\d{5}_./, tmp = nme.split(""); 

checkAndSave();

I had been trying to read the letters as digits. 

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
Community Expert ,
Jun 09, 2017 Jun 09, 2017

Copy link to clipboard

Copied

LATEST

Regex is not easier way off. You should understand the syntax before.

Try this snippet (standalone):

var a = "1234567_A";

var b = "ZZ12345_A";

var  nme = a.replace(/\.[^\.]+$/,""), reg = /^\w{2}\d{5}_./, tmp = nme.split("");

checkAndSave();

nme = b.replace(/\.[^\.]+$/,""), reg = /^\w{2}\d{5}_./, tmp = nme.split("");

checkAndSave();

nme = a.replace(/\.[^\.]+$/,""), reg = /^[A-Z]{2}\d{5}_./, tmp = nme.split("");

checkAndSave();

nme = b.replace(/\.[^\.]+$/,""), reg = /^[A-Z]{2}\d{5}_./, tmp = nme.split("");

checkAndSave();

function checkAndSave() { 

    if( reg.test( nme ) == false) { 

        alert (reg+" better regex do not find: "+ nme); return; } 

    else { alert (reg+" found: "+nme) }

    }

The reason is: \w will find all "word signs" eg digits AND letters

Have fun

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