1

IOError: [Errno 2] No such file or directory error を受け取りました。どこに問題があるのか​​わかりません。ディレクトリを確認したところ、ファイルが存在します。また、このプログラムを多数のテキスト ファイルで実行しようとしています。他に問題がないかどうかを確認していただければ幸いです。

import glob
import os
import shutil
import fileinput
import arcpy
from arcpy import env
env.workspace = "h:/Python scripts/Tests2"

list_of_files = glob.glob("h:/Python scripts/Tests2/*.txt")
root_path = 'h:/Python scripts/Tests2/'

for file_name in list_of_files:
    input = open(file_name, 'r')   
    output = open(file_name.replace('.txt', 't2.csv'), "w")  
    for line in input:       
        str = line.strip("    dd/mm/yyyy hh:mm:ss         kA\t")
        str = str.replace("date", "ddmmyyyy,hhmmss")
        str = str.replace(" lat.    long.   amp.", " lat,long,ka")
        str = str.replace("id   ", "id,")
        str = str.replace(" ", ",")
        str = str.replace(" ", ",")
    output.write(str)
    input.close()
    output.close()


root_path2 = 'h:/Python scripts/Tests2/'
infile = arcpy.ListFiles("*t2.csv")
coordinatesys = 'H:\Python scripts\modeltests\NAD 1983.prj'
#infile = glob.glob("h:/Python scripts/Tests2/*scv.txt")
for file_name2 in infile:
    print infile
    print file_name2

    out_name = file_name2.replace('t2.csv', 'p2.shp')
    arcpy.CreateFeatureclass_management(root_path2, out_name, "Point", "", "DISABLED", "DISABLED", coordinatesys)
    arcpy.AddField_management(out_name, "ddmmyyyy", "TEXT")
    arcpy.AddField_management(out_name, "hhmmss", "TEXT")
    arcpy.AddField_management(out_name, "lat", "LONG")
    arcpy.AddField_management(out_name, "long", "LONG")
    arcpy.AddField_management(out_name, "ka", "LONG")

    print out_name    

    CsvTrack = open(file_name2, "r")

    headerLine = CsvTrack.readline()
    valueList = headerLine.strip().split(",")
    print valueList

    daysValueIndex = valueList.index("ddmmyyyy")
    timeValueIndex = valueList.index("hhmmss")
    latValueIndex = valueList.index("lat")
    lonValueIndex = valueList.index("long")
    kaValueIndex = valueList.index("ka")

    cursor = arcpy.InsertCursor(out_name)
    for Rows in CsvTrack.readlines():
        segmentedPoint = Rows.split(",")
        daysValue = segmentedPoint[daysValueIndex]
        timeValue = segmentedPoint[timeValueIndex]
        latValue = segmentedPoint[latValueIndex]
        lonValue = segmentedPoint[lonValueIndex]
        kaValue = segmentedPoint[kaValueIndex]
        vertex = arcpy.CreateObject("Point")
        vertex.X = lonValue
        vertex.Y = latValue
        feature = cursor.newRow()      
        feature.days = daysValue
        feature.time = timeValue
        feature.shape = vertex
        feature.ka = kaValue
        cursor.insertRow(feature)
    del cursor`

具体的なエラーは次のとおりです。

Traceback (most recent call last):
File "C:\Python27\Lib\site-packages\pythonwin\pywin\framework\scriptutils.py", line   325, in RunScript
exec codeObject in __main__.__dict__
File "H:\Python scripts\Script1.py", line 45, in <module>
CsvTrack = open(file_name2, "r")

IOError: [Errno 2] そのようなファイルまたはディレクトリはありません: u'20060705t2.csv'

4

1 に答える 1