I have a folder containing hundreds of tif and related extension files e.g. NS26.tif, NS26.aux and NS26.rrd. I want to rename them adding a suffix i.e. NS26_c.tif, NS26_c.aux etc. I can manage this using filecopy to the existing folder but because the filename has changed overwrite won't work so I end up with new and old in same folder. Any suggestions?
Is there a quick way to rename files?
- March 22, 2017
- 14 replies
- 1508 views
- 1 reply
Best answer by takashi
Hi @chris_fc, try setting MOVE to the File Operation parameter of the File Copy writer.
It may be an old question, an answered question, an implemented idea, or a notification-only post.
Please check post dates before relying on any information in a question or answer.
For follow-up or related questions, please post a new question or idea.
If there is a genuine update to be made, please contact us and request that the post is reopened.
14 replies
- Contributor
- 2179 replies
- March 22, 2017
You can use the "Directory and File Path" reader to scan a folder (and subfolders) to retrieve the file names.
Then use the BulkAttributeRenamer to rename the file names and as you mentioned the FileCopy writer to move (or copy) the files to a new location.
- 7829 replies
- Best Answer
- March 22, 2017
Hi @chris_fc, try setting MOVE to the File Operation parameter of the File Copy writer.
- Contributor
- 605 replies
- March 22, 2017
Using "filecopy" to another folder is best option else using thru command prompt can also can be done
- Contributor
- 120 replies
- March 22, 2017
You can also use SystemCaller and type in command line for each tif, aux and rrd file of feature you read.
- Contributor
- 61 replies
- March 22, 2017
I'd break into a piece of python to do this, using pythoncaller - otherwise you're copying the data rather than quite a simple directory registry change?
google renaming file in python
but it's basically one line os.rename, if you're not comfortable in python then create the new name in transformers before you pass it to the pythoncaller.
you might wrap the rename function in a python 'try' stamen to catch any unexpected errrors, the file not being found or locked or something.
- Author
- 1 reply
- March 22, 2017
Hi @chris_fc, try setting MOVE to the File Operation parameter of the File Copy writer.
Chris
- 52 replies
- March 22, 2017
you can easily do it in python like nrich says. I do this in my workbenches to help define it being processed
1import fme2import fme objects3import os45original_file_name = 'orig_file_name.txt'6new_file_name = "new_file_name.txt"7orig_file_path =" directory path"8new_file_path = 'new_directory_path_if_file_moved"910os.rename(os.path.join(orig_path, original_file_name), os.path.join(orig_path, new_file_name)111213
You can then add parameters to hold the new_file and orig_file name so its more dynamic. Also the path you can have as a parameter. I think python is very easy and quick. You can always tie the directory path to the file name and get rid of os.path.join() and you would just need the file names for os.rename. Below is a stackoverflow that is a good example.
http://stackoverflow.com/questions/2491222/how-to-rename-a-file-using-python
- 25 replies
- October 17, 2018
Hello,
A follow up to this question: I am trying to rename X number of folders and I am using the following code:
def changeFolder(feature):
origVal=feature.getAttribute('path_windows')
fixVal=feature.getAttribute('pathwithoutcomma')
os.rename(origVal,fixVal)
pass
However, there is no change in the folders. The path_windows and pathwithoutcomma are values I have created inside FME.
Any ideas?
Thank you,
George
- 8386 replies
- October 17, 2018
Hello,
A follow up to this question: I am trying to rename X number of folders and I am using the following code:
def changeFolder(feature):
origVal=feature.getAttribute('path_windows')
fixVal=feature.getAttribute('pathwithoutcomma')
os.rename(origVal,fixVal)
pass
However, there is no change in the folders. The path_windows and pathwithoutcomma are values I have created inside FME.
Any ideas?
Thank you,
George
Try using shutil.move() rather than os.rename() and see if that helps.
- 25 replies
- October 18, 2018
Try using shutil.move() rather than os.rename() and see if that helps.
Thank you for your reply. Unfortunately it did not work. I am attaching a screenshot of my code and the inspector to make things more clear.
Thank you very much for your help.
Kind regards,
George
inspector.jpgcode.jpg
- 8386 replies
- October 18, 2018
Thank you for your reply. Unfortunately it did not work. I am attaching a screenshot of my code and the inspector to make things more clear.
Thank you very much for your help.
Kind regards,
George
inspector.jpgcode.jpg
You can delete everything from after the line containing "shutil.move(...)" and down.
- 25 replies
- October 23, 2018
You can delete everything from after the line containing "shutil.move(...)" and down.
Edit: I just realized I downvoted your answer? My impression was I pressed the Like button. This was my intention, your answer was 100% right and solved my problem.
- 8386 replies
- October 23, 2018
Edit: I just realized I downvoted your answer? My impression was I pressed the Like button. This was my intention, your answer was 100% right and solved my problem.
- Contributor
- 16 replies
- February 18, 2021
you can easily do it in python like nrich says. I do this in my workbenches to help define it being processed
1import fme2import fme objects3import os45original_file_name = 'orig_file_name.txt'6new_file_name = "new_file_name.txt"7orig_file_path =" directory path"8new_file_path = 'new_directory_path_if_file_moved"910os.rename(os.path.join(orig_path, original_file_name), os.path.join(orig_path, new_file_name)111213
You can then add parameters to hold the new_file and orig_file name so its more dynamic. Also the path you can have as a parameter. I think python is very easy and quick. You can always tie the directory path to the file name and get rid of os.path.join() and you would just need the file names for os.rename. Below is a stackoverflow that is a good example.
http://stackoverflow.com/questions/2491222/how-to-rename-a-file-using-python
Working example on what it looks like in a pythonCaller:
I have a folder containing hundreds of tif and related extension files e.g. NS26.tif, NS26.aux and NS26.rrd. I want to rename them adding a suffix i.e. NS26_c.tif, NS26_c.aux etc. I can manage this using filecopy to the existing folder but because the filename has changed overwrite won't work so I end up with new and old in same folder. Any suggestions?
You can use the "Directory and File Path" reader to scan a folder (and subfolders) to retrieve the file names.
Then use the BulkAttributeRenamer to rename the file names and as you mentioned the FileCopy writer to move (or copy) the files to a new location.
Hi @chris_fc, try setting MOVE to the File Operation parameter of the File Copy writer.
Using "filecopy" to another folder is best option else using thru command prompt can also can be done
You can also use SystemCaller and type in command line for each tif, aux and rrd file of feature you read.
I'd break into a piece of python to do this, using pythoncaller - otherwise you're copying the data rather than quite a simple directory registry change?
google renaming file in python
but it's basically one line os.rename, if you're not comfortable in python then create the new name in transformers before you pass it to the pythoncaller.
you might wrap the rename function in a python 'try' stamen to catch any unexpected errrors, the file not being found or locked or something.
Hi @chris_fc, try setting MOVE to the File Operation parameter of the File Copy writer.
Chris
you can easily do it in python like nrich says. I do this in my workbenches to help define it being processed
1import fmeimport fme objectsimport osoriginal_file_name = 'orig_file_name.txt'new_file_name = "new_file_name.txt"orig_file_path =" directory path"new_file_path = 'new_directory_path_if_file_moved"os.rename(os.path.join(orig_path, original_file_name), os.path.join(orig_path, new_file_name)
You can then add parameters to hold the new_file and orig_file name so its more dynamic. Also the path you can have as a parameter. I think python is very easy and quick. You can always tie the directory path to the file name and get rid of os.path.join() and you would just need the file names for os.rename. Below is a stackoverflow that is a good example.
http://stackoverflow.com/questions/2491222/how-to-rename-a-file-using-python
Hello,
A follow up to this question: I am trying to rename X number of folders and I am using the following code:
def changeFolder(feature):
origVal=feature.getAttribute('path_windows')
fixVal=feature.getAttribute('pathwithoutcomma')
os.rename(origVal,fixVal)
pass
However, there is no change in the folders. The path_windows and pathwithoutcomma are values I have created inside FME.
Any ideas?
Thank you,
George
Hello,
A follow up to this question: I am trying to rename X number of folders and I am using the following code:
def changeFolder(feature):
origVal=feature.getAttribute('path_windows')
fixVal=feature.getAttribute('pathwithoutcomma')
os.rename(origVal,fixVal)
pass
However, there is no change in the folders. The path_windows and pathwithoutcomma are values I have created inside FME.
Any ideas?
Thank you,
George
Try using shutil.move() rather than os.rename() and see if that helps.
Try using shutil.move() rather than os.rename() and see if that helps.
Thank you for your reply. Unfortunately it did not work. I am attaching a screenshot of my code and the inspector to make things more clear.
Thank you very much for your help.
Kind regards,
George
inspector.jpgcode.jpg
Thank you for your reply. Unfortunately it did not work. I am attaching a screenshot of my code and the inspector to make things more clear.
Thank you very much for your help.
Kind regards,
George
inspector.jpgcode.jpg
You can delete everything from after the line containing "shutil.move(...)" and down.
You can delete everything from after the line containing "shutil.move(...)" and down.
Edit: I just realized I downvoted your answer? My impression was I pressed the Like button. This was my intention, your answer was 100% right and solved my problem.
Edit: I just realized I downvoted your answer? My impression was I pressed the Like button. This was my intention, your answer was 100% right and solved my problem.
you can easily do it in python like nrich says. I do this in my workbenches to help define it being processed
1import fmeimport fme objectsimport osoriginal_file_name = 'orig_file_name.txt'new_file_name = "new_file_name.txt"orig_file_path =" directory path"new_file_path = 'new_directory_path_if_file_moved"os.rename(os.path.join(orig_path, original_file_name), os.path.join(orig_path, new_file_name)
You can then add parameters to hold the new_file and orig_file name so its more dynamic. Also the path you can have as a parameter. I think python is very easy and quick. You can always tie the directory path to the file name and get rid of os.path.join() and you would just need the file names for os.rename. Below is a stackoverflow that is a good example.
http://stackoverflow.com/questions/2491222/how-to-rename-a-file-using-python
Working example on what it looks like in a pythonCaller:
Related Topics
How can I write features to a temporary table with a Postgres writer?icon
AuthoringHow can I make a POST request send the Access-Control-Allow-Origin response header (job submit)icon
IntegrationHow do I send a log file as an email attachment in FME Sever Automations?icon
AutomationGoogle Drive token refresh fails through http/https proxy.icon
IntegrationHow to filter jobs by queue? How to sort the grid by 1 column or multiple columns?icon
Transformers
Helpful Members This Week
- hkingsbury
21 votes
- virtualcitymatt
8 votes
- liamfez
8 votes
- alexbiz
7 votes
- ebygomm
7 votes
- redgeographics
6 votes
- chriswilson
6 votes
- david_r
5 votes
- crutledge
5 votes
- DanAtSafe
5 votes
Recently Solved Questions
Community Stats
- 31,927
- Posts
- 121,264
- Replies
- 39,553
- Members
Latest FME
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.
Scanning file for viruses.
Sorry, we're still checking this file's contents to make sure it's safe to download. Please try again in a few minutes.
OKThis file cannot be downloaded
Sorry, our virus scanner detected that this file isn't safe to download.
OKCookie policy
We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.
Cookie settings
We use 3 different kinds of cookies. You can choose which cookies you want to accept. We need basic cookies to make this site work, therefore these are the minimum you can select. Learn more about our cookies.