I have a script that I use to convert text files into LAS files- there are 400 files. How would I make a batch script or loop to tell Python to keep grabbing the next file and keep converting until it reaches the end of the folder?
Solved! Go to Solution.
You can loop through a folder to get all your text files.
import os folder= r'path_to_your_folder_of_text_files' for root, dirs, files in os.walk(folder): for filename in files: input_file = os.path.join(root, filename) # You can then run your conversion script here # Use input_file for your input into your script.
I would look into using arcpy.da.walk.
Or, since this isn't ESRI data specific, you can use regular old os.walk.
Hi Jackie,
You could try something like the following:
import os for filename in os.listdir('dirname'): if os.path.isfile(filename): # code to convert file here
You can loop through a folder to get all your text files.
import os folder= r'path_to_your_folder_of_text_files' for root, dirs, files in os.walk(folder): for filename in files: input_file = os.path.join(root, filename) # You can then run your conversion script here # Use input_file for your input into your script.