0

I have a folder that contains text files that are essentially space-delimited CSVs, but have a file extension that ArcGIS Pro doesn't work with natively. I want to build a model that iterates over the folder and runs the "Export Table" geoprocessing tool on each of these files to convert them into a format that I can then run some other tools on.

Is there some way to have Pro convert the file into a CSV within ModelBuilder?

2
  • The main problem with ModelBuilder is that you sometimes try to find complex/expensive ways to do something that six lines of Python could accomplish, just to avoid Python.
    – Vince
    Commented Sep 16, 2023 at 0:00
  • Thanks Vince, you were absolutely right -- I was stuck in the Esri mentality and completely ignored Python. With your note and some tweaks to the code GBG provided in their answer, I was able to get my workflow humming right along. Commented Sep 19, 2023 at 18:37

1 Answer 1

0

As Vince states you could just use a simple Python script to rename the files. Easy as setting the paths to your directory and changing txt to your file extension in the code below. Then you can run the code in your ArcGIS Python window or your favorite Python IDE.

If you need to use a toolbox tool the code below can easily be incorporated into whatever you are developing.

Of course this renames the files so you might want to have originals someplace else.

import os
directory = r"C:\Temp\your_directory"
for f in os.listdir(directory):
    if f.endswith('.txt'):
        fullpath = os.path.join(directory,f)
        print(fullpath, fullpath[:-4]+'.csv')
        os.rename(fullpath, fullpath[:-4]+'.csv')
2
  • Much appreciated - this worked perfectly. Commented Sep 19, 2023 at 18:37
  • doh off by one line ;)
    – Vince
    Commented Sep 19, 2023 at 20:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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