次のディレクトリ/ファイルのセットアップがあります (これは簡略化されています)。
Ce
+---top.txt
+---X0.0
| |
| +---Y0.0
| | |
| | +---X0.0Y0.0Z0.0.dat
| | +---X0.0Y0.0Z0.05.dat
| +---Y0.05
| |
| +---X0.0Y0.05Z0.0.dat
| +---X0.0Y0.05Z0.05.dat
+---X0.05
|
+---Y0.0
| |
| +---X0.0Y0.0Z0.0.dat
| +---X0.0Y0.0Z0.05.dat
+---Y0.05
|
+---X0.0Y0.05Z0.0.dat
+---X0.0Y0.05Z0.05.dat
各 Y ディレクトリ内で、.dat ファイルのリストをファイル「top.txt」のコピーに追加する「psub」ファイルを作成する必要があります。
Python 3 で os.walk 関数を使用してこれを実行しようとしています: ただし、2 つの問題が発生しています:
1. 新しい psub ファイルが X0.0 ディレクトリに表示される
2. コードにファイル名が表示されない (おそらくX0.05 ディレクトリが見つからないというエラーが表示されます。
これまでのところ、次のコードがあります。
import os
with open('top.txt', 'r') as reader:
data=reader.read()
for root, dirs, files in os.walk('.'):
for folder in dirs:
os.chdir(os.path.join(root, folder))
with open('psub', 'a') as writer:
writer.write(data)
for names in files:
if names.endswith('.dat'):
print('gulp <' + names + '> ', end='', file=writer)
print(names.rsplit('.',1)[0], end='', file=writer)
print('.out', file=writer)
結果の psub ファイルは次のようになります。
#!/bin/bash
#MOAB -l walltime=48:00:0
#MOAB -j oe
#MOAB -N GULP-job
cd "$PBS_O_WORKDIR"
module load apps/gulp
#!/bin/bash
gulp <X0.00Y0.00Z0.00.dat> X0.00Y0.00Z0.00.out
gulp <X0.00Y0.00Z0.05.dat> X0.00Y0.00Z0.05.out
最初の 7 行は top.txt にあります。
私がどこで間違っているかについての(単純な)ポインタは大歓迎です。乾杯