Notifications
Clear all

[Closed] Creating new folder and reducing strings

Hi,

I’m trying to create a script to batch send out max files to network render. All my files are named with “_00” ( eg. “3456_00.max” “12_01.max” ) .

I need to output the targa sequence to individual folders named after the max files
(eg. “3456_00.max” will render to “c:/3456/3456_.tga)

Is there anyway to

  1. remove the last 3 characters of a string? i tried using substring but the total number of characters differs in each max file.

  2. create a new folder to a specific directory with a given name using maxscript?

Thanks in advance for any replies

4 Replies
  1. Substring is your best choice, but you need to play around with it a little.

You could try;


   file = "3456_00.max"
   newName = getFilenameFile file -- returns "3456_00"
   if (findstring newName "_") != undefined then (
 	newName = substring newName 1 (findstring newName "_")
   )
 
   format "%
" newName -- outputs "3456_"

You could also try


   file = "3456_00.max"
   values = filterstring file "_" -- returns #( "3456", "00" )
   newName = values[1] + "_"
 

Now obviously, it’s up to you to decide on which approach best meets your needs

  1. Again, same problem as above…with just one more line of code;

   file = "3456_00.max"
    values = filterstring file "_" -- returns #( "3456", "00" )
    newName = values[1] + "_"
 
[b]   makedir ("C:\\" + values[1]) -- creates a new dir "C:\3456"[/b]
  

Hope that clears up some of the issues for you

Shane

substring maxfilename 1 (maxfilename.count - 3)
makeDir  <directory_path_string>

Hi guys,

Thanks for your help. I finally got the script running. Its amazing to see max running on its own sending out all the files to render I can’t imagine how much time would be wasted if i were to send them manually (4000 files in all!)

RustyKnight :

Am I right to say that the first code uses substring from the first character to “” and the second code removes the “” and takes the first part of the 2 result? Can u please explain why is this line of code needed :

                if (findstring newName "_") != undefined then

I assume its for preventing error but can’t figure out why.

Gravy :

[left]substring maxfilename 1 (maxfilename.count – 3)[/left]
[left] [/left]
Simple and works great!

I missed the makeDir command cause all the while I’m been seaching the help file and forum for “create folder”. noob!

Thanks again for the help guys!

Hay Monotoner, great to hear you got it working.

You’re right, the first example cuts the string at the first occurance of ““, truncating the rest. The if statement just makes sure that there is a “” character in the string, otherwise findstring will return undefined, which will cause you problems if no “_” character exists in the string. I know you said all the files had it, but I never like taking the chance…to many bad experiences.

The second example splits the string at the “_” character. This allows you to get all the characters before and after the token. It’s slightly more safe then substring, cause if the token does not exist, you will simply get the whole string in the first array element.

Both these examples do not depend on the file extension or numeric values been known, so you could apply the script to just about any file that have a _.* pattern. When working with files, it is best not assume a 3 letter extension, it will always come back to bite you eventually.

As general experience has taught me, the requirements change, without notice and only AFTER you’ve pulled all you hair out trying to get the first set of requirements done…

Shane