You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello! I've struggled with this a bit and need some help. I can't figure out why the program listed above won't run--Aleks indicated it should work, but it gives me the following error on a PC (I am doing essentially the same task, just changing GA to GR instead of LN to LR):
Traceback (most recent call last):
File "rename_GA_GR.py", line 16, in
with open(full_name, 'r') as f:
FileNotFoundError: [Errno 2] No such file or directory: 'test_files\GA\1\108_GA_1_NA_1_F_10539_UA.txt'
Thanks in advance for your help!
The text was updated successfully, but these errors were encountered:
@slstaples , I was able to reproduce the error you're seeing on a Mac.
The reason this is happening is that part of the script is still trying to process a filename which a previous part of the script has already renamed (i.e., the file changed 108_GA_1_NA_1_F_10539_UA.txt' to 108_GR_1_NA_1_F_10539_UA.txt', so, in effect the error is correct -- the file can no longer be found, and it therefore can't complete the operation of manipulating the header (<Assignment: GA>).
Looking at the code, this can be resolved by flipping the order of operations: first manipulate the header, then rename the file. I've shown the code change in a diff below, if that's useful for reference. This order of operations change should be made to the existing rename_LN_LR.py as well as to the new script you're working on, rename_GA_GR.py.
Let me know if you have any additional questions!
diff --git a/fix_headers/renameLN_LR.py b/fix_headers/renameLN_LR.py
index a4a44bc..a728fbc 100755
--- a/fix_headers/renameLN_LR.py+++ b/fix_headers/renameLN_LR.py@@ -10,8 +10,6 @@ args = parser.parse_args()
for root, dirs, files in os.walk(args.dir):
for fileName in files:
full_name= os.path.join(root,fileName)
- if "_LN_" in full_name:- os.rename(full_name, full_name.replace("_LN_", "_LR_"))
if ".txt" in full_name:
with open(full_name, 'r') as f:
s= f.read()
@@ -20,5 +18,6 @@ for root, dirs, files in os.walk(args.dir):
with open(full_name, "w") as f:
f.write(s)
f.close()
--+ if "_LN_" in full_name:+ os.rename(full_name, full_name.replace("_LN_", "_LR_"))+
Hello! I've struggled with this a bit and need some help. I can't figure out why the program listed above won't run--Aleks indicated it should work, but it gives me the following error on a PC (I am doing essentially the same task, just changing GA to GR instead of LN to LR):
Traceback (most recent call last):
File "rename_GA_GR.py", line 16, in
with open(full_name, 'r') as f:
FileNotFoundError: [Errno 2] No such file or directory: 'test_files\GA\1\108_GA_1_NA_1_F_10539_UA.txt'
Thanks in advance for your help!
The text was updated successfully, but these errors were encountered: