- #1
joshmccraney
Gold Member
- 2,253
- 143
Hi PF!
There are directories 0 5 10 15 20 (and so on), each containing a single volFieldValue.dat file (same name in each directory). I would like to successively combine each .dat file into one. So far what I have is this:
but I'm getting the error
Your help is greatly appreciated!
There are directories 0 5 10 15 20 (and so on), each containing a single volFieldValue.dat file (same name in each directory). I would like to successively combine each .dat file into one. So far what I have is this:
Python:
#!/usr/bin/python3
import numpy as np
#-----------------------SCRIPT DESCRITION-----------------------#
# THIS SCRIPT MERGES ALL .dat FILES FOR POST-PROCESSING
#---------------------------------------------------------------#
# Create a list of DIRECTORY NAMES
first_dir = 5
last_dir = 20
increment = 5
dirNames = np.arange(first_dir, last_dir, increment)
print(len(dirnames)
# LOOP THROUGH ALL DIRECTORIES
for j in range(0, len(dirNames))
# OPEN volFieldValue.dat IN THE DIRECTORY ./0/ IN WRITE MODE
with open('./0/volFieldValue.dat', 'w') as outfile:
# OPEN EACH SUCCESSIVE FILE IN READ MODE
with open('./'+str(dirNames(j))+'/volFieldValue.dat') as infile:
# READ DATA FROM SUCCESSIVE FILE AND WRITE IN ./0/volFieldValue.dat
outfile.write(infile.read())
# LINEBREAK TO SEPARATE SUCCESSIVE FILES
outfile.write("\n")
but I'm getting the error
Code:
File "file_merge.py", line 20
with open('./0/volFieldValue.dat', 'w') as outfile:
^
SyntaxError: invalid syntax
Your help is greatly appreciated!
Last edited: