-
1. Re: Incremental Numbering for File Names
Michael L Hale May 15, 2013 9:57 AM (in response to adraft)From that error message I would say that you have a bad file path. The saveAs() command will not create subfolders if they do not exists. At a guess you are trying to create a new folder and save to that folder in one step. You need to first create the folder, then you can save to it.
Or if the D: drive on your system is a CD/DVD drive then that may be the problem.
-
2. Re: Incremental Numbering for File Names
adraft May 15, 2013 10:19 AM (in response to Michael L Hale)Thank you for your response. The script only works for me when I have it save to a folder, which is fine. For some reason specifying subfolders (already existing ones) brings up that error message again.
This will work for me, though. Thanks again.
-
3. Re: Incremental Numbering for File Names
Michael L Hale May 15, 2013 10:47 AM (in response to adraft)You should be able to save to an existing subfolder unless it's a folder that can't be written to because of user permissions.
Can you post the line that defines 'saveFile'? It could be that you are not creating the path correctly. It's had to tell from the error message as some of the path looks like it was replaced with '...'
-
4. Re: Incremental Numbering for File Names
adraft May 15, 2013 10:53 AM (in response to Michael L Hale)var saveFile = new File( saveFolder + '/' + saveName + '_' + zeroPad( saveNumber, saveSufixLength ) + '.' + saveExt );
and for saveFolder I've got:
var saveFolder = new Folder( 'D:\Civil War\Process\Screen Caps' );
the script works when the path is D:\Civil War, but when I enter any subfolders I get the error.
-
5. Re: Incremental Numbering for File Names
Michael L Hale May 15, 2013 11:59 AM (in response to adraft)The backslash in javascript is a special char used to escape the following char. So either use
var saveFolder = new Folder( 'D:\\Civil War\\Process\\Screen Caps' );
Or better yet avoid the unnecessary use of the special char.
var saveFolder = new Folder( '/D/Civil War/Process/Screen Caps' );
-
6. Re: Incremental Numbering for File Names
adraft May 15, 2013 12:00 PM (in response to Michael L Hale)huzzah! thank you!
-
7. Re: Incremental Numbering for File Names
adraft May 15, 2013 2:31 PM (in response to adraft)Oops. For some reason after getting to file number _008, new saves are numbered _001 (and rewrite the existing _001). Any idea why this would be happening?
-
8. Re: Incremental Numbering for File Names
Michael L Hale May 15, 2013 4:52 PM (in response to adraft)It's hard to say without seeing your code but I would guess that there is something wrong with how 'saveNumber' is being created/updated.
You can avoid overwritting files by checking if they exists before the save step. If they don't exists it is safe to save. If they do exists then you have to modify saveFile.
But I would fix the 'saveNumber' problem first. Fixing that may take care of overwritting.
-
9. Re: Incremental Numbering for File Names
adraft Jun 13, 2013 9:58 PM (in response to Michael L Hale)I got the script working. Took out some of the superfluous steps. Here it is in case anyone is curious:
// This script will save the active document to a folder with an incremental sufix
// Change the options below to match your needs
var saveFolder = new Folder( '/D/Civil War/Process/Screen Caps' );
var saveExt = 'tif';
var saveSufixStart = '_';
var saveSufixLength = 3;
tifOpts = new TiffSaveOptions();
tifOpts.embedColorProfile = true;
tifOpts.imageCompression = TIFFEncoding.NONE;
tifOpts.alphaChannels = false;
tifOpts.layers = false;
// End of user options
//==========================================
function zeroPad ( num, digit ){
var tmp = num.toString();
while (tmp.length < digit) { tmp = "0" + tmp;}
return tmp;
}
var docName = decodeURI ( activeDocument.name );
docName = docName.match( /(.*)(\.[^\.]+)/ ) ? docName = docName.match( /(.*)(\.[^\.]+)/ ) : docName = [ docName, docName, undefined ];
var saveName = docName[ 1 ]; // activeDocument name with out ext
var files = saveFolder.getFiles( saveName + '*.' + saveExt );// get an array of files matching doc name prefix
var saveNumber = files.length + 1;
alert("New file number: " + zeroPad( saveNumber, saveSufixLength ));
var saveFile = new File( saveFolder + '/' + saveName + '_' + zeroPad( saveNumber, saveSufixLength ) + '.' + saveExt );
activeDocument.saveAs( saveFile, tifOpts ,true ,Extension.LOWERCASE);


