Notifications
Clear all

[Closed] Sorting Filenames

ok I got an anoying bug here that I should be able to fix on my own. but i’m stuck…

I have two different file names that the script below is supposed to check for based on the user defined “save file name” in the folder. If it finds one it outputs the render with the file name + 1. This works great but not if I have two file names like this “scene_000001” and scene_scene_000005″ The first part of the name is the maxscene name, the second is the name. The script removes everything but the last element in the array and uses that 00000 # to save the files with an incremental value. I need to some how seperate “scene_scene” from “scene” so its not counted?

if the the user sets a save file name “scene” then the script will count both the files “scene_scene” and “scene” which throws off the file naming. In the example above it would save a new file called “scene_000006”

I tried finding “scene” in the array but it only find the first one… and I tried filterstring but it removes all instances of “scene”. Maybe the problem is with get files but I think changing that may break script.

Any ideas?
Thanks!

This is part of bobo’s Rhistory script which I modified.


   ------------------------This is an array of supported image types to check for--------------------
   			local supportedtypes =
   			#(		
   				".avi",".mpg",".mpeg",".bmp",".cin",".cws",".gif",".hdri",".hdr",".pic",
   				".ifl",".jpg",".jpeg",".exr",".png",".psd",".mov",".rgb",".sgi", 
   				".rla",".rpf",".tga",".vda",".icb",".vst",".tif",".yuv",".dds"
   			 )
   			--------------------------------------------------------------------------------------------------
   		
   			------------------------Count all supported images from folder path using a loop command-----------
   			
   			Path = ((Image_Path)+"\\"+Prefix) --Path to save images to
   			local check_for_files = #()
   			for f in supportedtypes do -- The loop
   			join check_for_files (getFiles (Path+"*"+f)) -- Join each loop
   			
   			--------------------------------------------------------------------------------------------------			
   			
   			local out_file_name = if check_for_files.count == 0 then
   				
   				(Image_Path)+"\\"+Prefix+"_"+(RRH_GetZeros 1 6) + "1." + Image_Format
   				
   			else
   			(
   				--For backwards compatibility, we sort all image numbers using qsort:
   				--First we collect the numbers of all files found:
   				local sortArray = for f in check_for_files collect
   				(		
   						
   						local theFileName = getFileNameFile f  --get the filename
   						local base = trimleft thefilename Prefix
   						local theFS = filterString base "_"  --split by underscore delimiter
   						execute (theFS[theFS.count]) --convert the last element of the array to a number and return to collect
   				)
   			
   				local indexArray = for f = 1 to check_for_files.count collect f --collect all indices to sort by
   				qsort indexArray compareFN valArray:sortArray --sort the indices based on the corresponding file numbers
   				sortArray = for i in indexArray collect sortArray[i] --collect the new sorted array using the sorted indices
   				theFileNameNumber= sortArray[sortArray.count] + 1 --get the highest frame number and add one to it, then return the new file using that number
   				(Image_Path)+"\\"+Prefix+"_"+(RRH_GetZeros theFileNameNumber 6) + theFileNameNumber as string +"." + Image_Format
   			)
   
Page 2 / 2