1

I am attempting to write / run a simple script that list all the points within a directory, and the subdirectories contained within.

Here is the code:

import arcpy, os
workspace = r'c:\Users\athom\Documents\ArcGIS'
txtfile = r'c:\users\athom\desktop\PointList.txt' 
featureClass = []
for dirpath, dirnames, filesnames in arcpy.da.Walk (workspace, datatype = 'FeatureClass', type = 'Point'):
 for filename in filesnames:
 fc = featureClass.append (os.path.join(dirpath, filename))
 print featureClass
 openfile = open (txtfile,'a')
 openfile.write(str(fc) + '\n')
openfile.close()

The script appears to work fine, as it lists the points in the Python Interpreter at the bottom of the PyScripter.

The issue is with the output to the .txt file as it comes out as the features are written as this: ਍潎敮਍潎敮਍潎敮਍潎敮਍潎敮਍ over and over and over.

I copied the characters and pasted them into a word document, but they remain as strange characters.

If the script points to a directory with only a few point features, it still outputs the same characters.

Does anyone have any suggestions? I think it may be related to this question, but am not 100% certain.

asked Nov 7, 2014 at 21:42

1 Answer 1

3

You are writing out the list object into the .txt file, this is the byte representation so that is why it comes out all funky. I think this is what you meant to do:

import arcpy, os
workspace = r'c:\Users\athom\Documents\ArcGIS'
txtfile = r'c:\users\athom\desktop\PointList.txt' 
 featureClass = []
 for dirpath, dirnames, filesnames in arcpy.da.Walk (workspace, datatype = 'FeatureClass', type = 'Point'):
 for filename in filesnames:
 fc = os.path.join(dirpath, filename)
 featureClass.append(fc)
 print fc
 openfile = open (txtfile,'a')
 openfile.write(str(fc) + '\n')
 openfile.close()
answered Nov 7, 2014 at 22:15
3
  • I dropped the "fc = featureClass.append(os.path.join(dirpath, filename))" part in my code and the output to the .txt file worked, but it opened very slow. This method worked much better. Commented Nov 7, 2014 at 22:23
  • What I meant to say is that the "fc =" was dropped. Commented Nov 7, 2014 at 22:33
  • One thing that would also be more efficient would be to just write a new txt file instead of opening and appending the file at each iteration. You could use a with statement with the 'w' mode. Commented Nov 7, 2014 at 22:52

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.