Is there a way to get the file name of a image sequence, minus the frame padding? For example, the name of a file could be any of the following (and more):
temp/shot01_####.dpx
temp/shot01_#######.dpx
temp/shot01.#.dpx
How would I do to find just "shot01"? It would be hard to search the string and just ignore those characters, as there are so many possible naming conventions.
Also, is there a way to find the number of the first frame? For example, a image sequence could be imported as shot01_[0030-0050].dpx into AE, how would I know could I tell AE that the first frame is frame 30? Same problem here, as there are a number of possible naming conventions, it could just as well be shot01_[0000030-0000050].dpx.
Thank you.
Get file name of img seq except frame padding?
Moderator: Paul Tuersley
For the first problem, you could do something like the following:Simma wrote: temp/shot01_####.dpx
temp/shot01_#######.dpx
temp/shot01.#.dpx
How would I do to find just "shot01"? It would be hard to search the string and just ignore those characters, as there are so many possible naming conventions.
Two step process:
first, you isolate the file name:
Code: Select all
fName = fullPath.replace(/\\/g,'/').replace( /.*\//, '' );
Code: Select all
baseName = fName.split('.')[0];
Of course, this has no error correction, if the file does not have a file extension.
Let me make sure I understand. You want to find the beginning number of an imported file sequence?Also, is there a way to find the number of the first frame? For example, a image sequence could be imported as shot01_[0030-0050].dpx into AE, how would I know could I tell AE that the first frame is frame 30? Same problem here, as there are a number of possible naming conventions, it could just as well be shot01_[0000030-0000050].dpx.
.
If you have already have the sequence in a variable like "thisFileSeq":
Code: Select all
firstFileName = thisFileSeq.file.name;
Code: Select all
firstFileName.split('.')[0].split("_").pop();
Looking for the number without the underscore gets quite a bit more complicated.
-crg
Thanks for your reply zold. I played some with your suggestion but didn't get it to work. I might have done something wrong though, as it gave me the full file name.
I think I got it to work with this code in most cases at least:
I think I got it to work with this code in most cases at least:
Code: Select all
var fileName = "shot01_01_007";
// Put every character in an array.
var myArray = new Array();
for (var i = 0; i <= fileName.length - 1; i++){
myArray[myArray.length] = fileName.charAt(i -1 );
}
// Loop through the array (backwards) until a a character that isn't a number is found.
for(var i = myArray.length - 1; i>=0; i--){
var character = myArray[i].toString();
var noNumber = isNaN(character);
if(noNumber == true || character == "."){
var theNoNumber = i;
break;
}
}
// Subtract the frame padding from the filename.
var subtractNumber = myArray.length - theNoNumber + 1;
var myFileName = fileName.substring(0,fileName.length-subtractNumber);
alert("The filename without framepadding is: " + myFileName);
var firstFrame = parseFloat(fileName.slice(theNoNumber));
alert("The firsframe of the sequence is: " + firstFrame);
[UPDATE: Okay I just realized that using parseInt() is a very bad idea in this case, as using "padded" zeros is interpreted as octal (see http://www.w3schools.com/jsref/jsref_parseInt.asp -- "If the string begins with "0", the radix is 8 (octal). This feature is deprecated" [so even though it is deprecated, it still does this])
SORRY ABOUT THAT.
[UPDATE: DO NOT USE THIS TECHNIQUE; SEE ABOVE!]
[2nd UPDATE: THIS IS WHAT YOU SHOULD USE. PARSEFLOAT, NOT PARSEINT:]
Cheers!
SORRY ABOUT THAT.
"it" refers to what? Which suggestion didn't work? Running this in AE works for me, but maybe I'm missing something:Simma wrote:Thanks for your reply zold. I played some with your suggestion but didn't get it to work. I might have done something wrong though, as it gave me the full file name.
Code: Select all
n = "shot01_01_007".split('.')[0].split("_").pop();
//returns "007"
//then, to 'strip' the leading zeros:
//makes "007" into an integer, then back to string:
Code: Select all
n = (parseInt(n).toString());
alert(n);//should show "7"
Code: Select all
n = (parseFloat(n).toString());
alert(n);//should show "7"
and you could also use the regular expression solution (but if you want a number, parseInt it):
Code: Select all
n = "000100";
nAsString = (n.replace(/^[0]+/g,""));
//100 as string ("100")
nAsInteger = parseInt(nAsString);
// 100 as integer
- lloydalvarez
- Enhancement master
- Posts: 460
- Joined: June 17th, 2004, 9:27 am
- Location: New York City, NY
- Contact:
parseInt has an optional radix parameter (http://www.w3schools.com/jsref/jsref_parseInt.asp) so you would simply tell it you want it to parse the integer on a base of 10 like so:
parseInt("00007",10); //result: 7
I think having leading zero's is an undocumented way of defining an octal base which is probably why you are getting the unusual output. I would say it is good practice to always define the base when using parseInt. Also, if what you want is an integer use parseInt instead of parseFloat.
-Lloyd
parseInt("00007",10); //result: 7
I think having leading zero's is an undocumented way of defining an octal base which is probably why you are getting the unusual output. I would say it is good practice to always define the base when using parseInt. Also, if what you want is an integer use parseInt instead of parseFloat.
-Lloyd
-
- Posts: 30
- Joined: January 12th, 2012, 1:36 am
- Location: Ireland
- Contact:
Hi there, before I found this post I was working with some of these problems.
This is some code I had generated, I just said I would post it here for reference.
var testRegExp = new RegExp ("[0-9]+\.[A-Za-z]{1,3}$");
//will return 0023.tga for example...
var testString = app.project.item(i).mainSource.file.displayName;
//DO WE HAVE NUMBERS IN THE FILE THAT LOOK LIKE A SEQUENCE..?
var x =testRegExp.test(app.project.item(i).mainSource.file.displayName);
// IF WE DO , REPLACE THE MATCH WITH NOTHING...+ (seq)
if ( x == true){
//CURRENT STRING FOR ITEM
var curName =app.project.item(i).name;
//THE NEW STRING FOR ITEM
var newName = curName.replace(testRegExp," (Seq)");
//ASSIGN THE NEW STRING TO THE ITEM.
app.project.item(i).name = newName;
}//CLOSE IF.
This is some code I had generated, I just said I would post it here for reference.
var testRegExp = new RegExp ("[0-9]+\.[A-Za-z]{1,3}$");
//will return 0023.tga for example...
var testString = app.project.item(i).mainSource.file.displayName;
//DO WE HAVE NUMBERS IN THE FILE THAT LOOK LIKE A SEQUENCE..?
var x =testRegExp.test(app.project.item(i).mainSource.file.displayName);
// IF WE DO , REPLACE THE MATCH WITH NOTHING...+ (seq)
if ( x == true){
//CURRENT STRING FOR ITEM
var curName =app.project.item(i).name;
//THE NEW STRING FOR ITEM
var newName = curName.replace(testRegExp," (Seq)");
//ASSIGN THE NEW STRING TO THE ITEM.
app.project.item(i).name = newName;
}//CLOSE IF.