I am trying to rename a XXXX.out file into a XXXX.txt file for it to be read into the rest of my very large model that does other things. This ".out" really is a simple ".csv" file and once I have the extension on it renamed I do many great things to it. I have hundreds of them and they will be continued to be made in ".out" files.

So far the only way I've come up with doing this is Parse Path, but I can't figure out how to combine the end results into something that can get fed into the rest of my model.

I am pretty new to model building and python.

I've attached the screen shot of this very small portion of the model I have so far.


From tikinter import Tk
From tkFileDialog import askopenfilename
Import os, sys, tempfile, shutil


filename = askopenfilename(filetypes = ((“My Name”, “.out”), (“All files”, “*.*”),))
print (filename) #checking my work 

TempFolder = tempfile.mkdtemp()
Print TempFolder #check my work

Shut.copy2(filename, TempFolder)

For filesinfolder in os.listdir(TempFolder):
Infilename = os.path.join(TempFolder, filesinfolder)
If not os.path.isfile(infilename): continue
Oldbase = os.path.splitext(filesinfolder)
Newname = infilename.replace (‘.out’, ‘.txt’)
Output = os.rename(infilename, newname)

Print (newname) #checking my work and this give the whole path including the newly renamed text file.

  • Does "rename" work? It says that it will work on a table among other data types, so I don't know if it will rename a .csv or text file. – mkennedy Aug 9 '17 at 20:47
  • It does seem to be an option, but I was wanting this to happen in the background as this file is just used as a jumping off point. This seems to need user output, unless there is some tweek to this I'm missing? – ESmith Aug 9 '17 at 20:52
  • And just playing around with this option, it will not let me rename the extension portion to ".txt", keeps reverting back to ".out". – ESmith Aug 9 '17 at 21:00
  • Too bad. Googling python rename file has a lot of results like trying os.rename(). – mkennedy Aug 9 '17 at 21:01
  • And that maybe an serious option, but I'm pretty new to this. I can't figure out how to link the output of the python script to model input in the larger model. I get the part where you right click in ArcCatalog and select "Add Script", check the store relative's path name, add the script. The difficult part for me, is the parameter parts, I've added the input okay enough, but the output doesn't seem to hold the output value in the script. In order words I'm a total Newb and have no idea how to get this part to work. – ESmith Aug 9 '17 at 21:07

You can use the calculate value tool to run some python inside model builder. The model will be simply:


The calculate tool would contain the following code:

Calculate Value tool

  • 1
    This is the best option from within ArcMap. You could also write a simple standalone python script that you would run before running your model. With a for loop, you could rename all the .out in a folder to .txt or .csv. Just something else to think about. – jbalk Aug 10 '17 at 8:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.