AnsweredAssumed Answered

Cut a column, then write to a new file, different suffix

Question asked by huffmanp on Oct 24, 2012
Latest reply on Oct 25, 2012 by huffmanp
I need a little hint because I see now I don't understand enough about file input and output in Python.

I have some ascii lidar files that need to have the first column in each line removed to get them ready for the XYZI format of the ASCII 3D To Feature Class tool.  I wanted to make a list of all the files in a folder with the suffix .gnd and output the modified data to files with the same name but a txt suffix so the original ascii files were not modified.  What I got started with was:
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])

Then I was stuck. I guess I need a new line inside the first loop to write the file to a new file name with a .txt suffix, and I haven't even figured out how to get the file name stripped of the suffix. 

What I used to do was I had an XP machine with Unix services for Windows installed that somehow let me use the Linux cut command inside a dos bat file:
for %%f in (*.gnd) do call :sub %%f %%~nf  GOTO:EOF  :sub cut -d" " -f2-4 %1 > %2.txt

The DOS %~ can give you a lot of useful file name manipulations.  I installed Unix Services for Windows on a new Win 7 64 machine, and I don't understand why, but cut is not available to bat files on the new machine, although I can start a Unix C or K shell where cut is available but the %~n trick is not.