hi every one
I work in visual effects so I always work with image sequence like this:
out__Diffuse0050.tga
out__Diffuse0051.tga
…
I want to use a script to detect how many number their is in the last group of number
in the last group because files can be named in other way like this:
Got_Milk_001_MASTER_DEF-prores-25p_00000.tga
so I can’t use text delimiter to find digits because i don’t have a regular delimiter for every work
but the detection is the same for every files in a folder
set sourceFolder to (choose folder with prompt "Source files Folder") --the parent folder wich other folders inside
tell application "Finder"
set filesFolder to folder of sourceFolder --here it should detect every folder in the parent folder
set theFiles to files of filesFolder
repeat with aFile in theFiles
set {name:Nm, name extension:Ex} to aFile
set Nom to text 1 thru ((get offset of "." & Ex in Nm) - 1) of Nm
--Compte les lettres
set myNumber to number of myFile -- I don't find how to do here to reconize number
set myCount to count (myNumber)
set NomClr to text 1 thru ((get offset of "" & myNumber in Nom) - 1) of Nom
end repeat
end tell
set myFrames to "%0" & myCount & "d"
--display dialog myFrames
set SourceFiles to NomClr & myFrames
assuming the number portion is always at the end of the file name before the file extension,
this extracts the number by testing the ASCII value
set fileName to "out__Diffuse0159"
set foundNumber to ""
repeat with x from (count fileName) to 1 by -1
set characterX to character x of fileName
if id of characterX > 57 or id of characterX < 48 then exit repeat
set foundNumber to characterX & foundNumber
end repeat
foundNumber
ok thanks
with it, it’s more difficult (for me) to integrate it in an other repeat
how to apply multiple repeat with different value ?
an other thing
How i can do for detect files in folders contain in the selected folder ?
I’ve try set … to folder in … but that give the same result from … to folder of …
set sourceFolder to (choose folder with prompt "Source files Folder") --the parent folder wich other folders inside
set foundNumber to ""
tell application "Finder"
set filesFolder to folder in sourceFolder
--display dialog filesFolder
set theFiles to files of sourceFolder
set theSeqFile to files in filesFolder
--display dialog theSeqFile
repeat with aFile in theFiles -- & with x from (count fileName) to 1 by -1
set {name:Nm, name extension:Ex} to aFile
set Nom to text 1 thru ((get offset of "." & Ex in Nm) - 1) of Nm
set characterX to character x of Nom
if id of characterX > 57 or id of characterX < 48 then exit repeat
set foundNumber to characterX & foundNumber
set myCount to count (foundNumber)
set myFrame to "%0" & myCount & "d"
end repeat
end tell
you have a cupboard (sourceFolder) which contains some drawers (folders),
so you have to look into each drawer to process things (files)
set sourceFolder to (choose folder with prompt "Source files Folder") --the parent folder wich other folders inside
tell application "Finder"
set filesFolder to folders of sourceFolder
repeat with oneFolder in filesFolder
set theFiles to files of oneFolder
repeat with aFile in theFiles -- & with x from (count fileName) to 1 by -1
set foundNumber to ""
set {name:Nm, name extension:Ex} to aFile
set Nom to text 1 thru ((get offset of "." & Ex in Nm) - 1) of Nm
repeat with x from (count Nom) to 1 by -1
set characterX to character x of Nom
if id of characterX > 57 or id of characterX < 48 then exit repeat
set foundNumber to characterX & foundNumber
end repeat
set myCount to count (foundNumber)
set myFrame to "%0" & myCount & "d"
end repeat
end repeat
end tell
Note: the variable foundNumber must be reset for each new file
PS: If you don’t need the extracted string but only the number of characters,
the variable foundNumber is not needed
.
-- set foundNumber to ""
.
repeat with x from (count Nom) to 1 by -1
set characterX to character x of Nom
if id of characterX > 57 or id of characterX < 48 then exit repeat
end repeat
set myCount to (count Nom) - x
.
I’ve try it but that don’t work
that return and error "impossible to have file of “M”
i don’t have any files or folders name M…
moreover, the number count isn’t for all the content of a folder, every files have the same numbers of digits, it’s for every folder.
I expain why, In Nuke, file sequence are reconize by name%04d %04d is number of digits that why i want count them.
Each folder is a sequence with the same properties but that can be different from a folder to an other.
set sourceFolder to (choose folder with prompt "Source files Folder") --the parent folder wich other folders inside
tell application "Finder"
set filesFolder to folders of sourceFolder
repeat with oneFolder in filesFolder
set theFiles to files of oneFolder -- Problem with the "M" files is here !
repeat with aFile in theFiles -- with x from (count fileName) to 1 by -1
set foundNumber to ""
set {name:Nm, name extension:Ex} to aFile
set Nom to text 1 thru ((get offset of "." & Ex in Nm) - 1) of Nm
repeat with x from (count Nom) to 1 by -1
set characterX to character x of Nom
if id of characterX > 57 or id of characterX < 48 then exit repeat
set foundNumber to characterX & foundNumber
end repeat
set myCount to count (foundNumber)
set myFrame to "%0" & myCount & "d"
end repeat
end repeat
end tell