0

ファイル管理に問題があります。拡張子が .txt のファイルを検索する必要がありますが、パスは毎日変化しています。

実際のパスを含む別のファイルがあり、それを文字列に保存できますが、検索アルゴリズムを指定すると、ウィンドウにエラー メッセージが表示されます。

ここに私のスクリプト:

path= 'c:\..... this is the path what I get back from an another script'

os.chdir(path)
for files in os.listdir("."):``
    if files.endswith(".txt"):
        print files

エラー メッセージ: WindowsError: [エラー 3] 指定されたパスが見つかりません: 'c:....'

4

2 に答える 2

0

これを試して

path= 'c:/..... this is the path what I get back from an another script'

os.chdir(path)
for files in os.listdir("."):``
    if files.endswith(".txt"):
        print files

/それ以外の\

于 2012-10-03T17:43:56.193 に答える
0

トリックを行うためにこれを出します。

from glob import glob
from os.path import join

path = 'c:\\test'
print glob(join(path, '*.txt'))
于 2012-10-03T17:45:39.973 に答える