span8
span4
span8
span4
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?
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
you can easily do it in python like nrich says.I do this in my workbenches to help define it being processed
import 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
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.
You can also use SystemCaller and type in command line for each tif,aux and rrd file of feature you read.
Using "filecopy" to another folder is best option else using thru command prompt can also can be done
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.
© 2019 亚搏在线Safe Software Inc |Legal