env.workspace = "G:/elevation/lidar2010/points/asc_grounds" fileSuffix = ".gnd" txtList = arcpy.ListFiles("*" + fileSuffix) for file in txtList: for line in open("my file"): parts = line.split(" ") print " ".join(parts[1:4])
for %%f in (*.gnd) do call :sub %%f %%~nf GOTO:EOF :sub cut -d" " -f2-4 %1 > %2.txt
Solved! Go to Solution.
import glob import os.path workdir = "G:/elevation/lidar2010/points/asc_grounds/" fileSuffix = ".gnd" outSuffix = ".txt" fileList = glob.glob( workdir+"*"+fileSuffix ) for f in fileList: name, ext = os.path.splitext( f ) infile = open( f, "r" ) outfile = open( name+outSuffix, "w" ) for line in infile: print >> outfile, " ".join( line.strip().split(" ")[1:4] ) outfile.close() infile.close()
and I haven't even figured out how to get the file name stripped of the suffix.
import os NameMinusExt = os.path.splitext("TheFileName.gnd")[0]
txtList = arcpy.ListFiles("*" + fileSuffix) for file in txtList: newFile = os.path.splitext(file)[0] + ".txt" ###...or maybe? newFile = str(os.path.splitext(file)[0]) + ".txt"
for f in *.gnd; do cut -d' ' -f2-4 "$f" > "${f%.*}.txt"; done
import arcpy import os arcpy.env.workspace = r"G:\elevation\lidar2010\points\asc_grounds" fileSuffix = ".gnd" fileList = arcpy.ListFiles("*" + fileSuffix) for f in fileList: print "Processing file", f, "..." # Text File to Write Out txtFile = os.path.splitext(f)[0] + ".txt" fobj = open(txtFile, 'w') for line in open(f): parts = line.split(" ") fobj.write(" ".join(parts[1:4])) fobj.close()
import glob import os.path workdir = "G:/elevation/lidar2010/points/asc_grounds/" fileSuffix = ".gnd" outSuffix = ".txt" fileList = glob.glob( workdir+"*"+fileSuffix ) for f in fileList: name, ext = os.path.splitext( f ) infile = open( f, "r" ) outfile = open( name+outSuffix, "w" ) for line in infile: print >> outfile, " ".join( line.strip().split(" ")[1:4] ) outfile.close() infile.close()