06-14-2011 04:34 AM
Hi,
After an exhausting search of this forum and a lot of trial-and-error, I have not been able to work out how to rename a .csv file. For example, i want to change the name of the csv files in a folder to include the name of the folder. E.g. From Trial01 to Folder1_Trial01.
Can someone help me, please!
Thanks
CJ
Solved! Go to Solution.
06-14-2011 04:54 AM
CJ,
what version of LV are you using?
In general, this is rather simple:
Open the file with file open, copy it to the new location/name and then delete the original file. If this seems rather overelaborate to you, you have to use Windows SDK commands for this (or use .NET or any other API delivering a dedicated "rename"-function), which will result in more complex code.
hope this helps,
Norbert
06-14-2011 05:25 AM
Hi Norbert,
I am using Student version 9.0.1.
Thanks,
CJ
06-14-2011 05:31 AM
Also, I have used the move file function however, it doesn't like the source path name even though there aren't any characters that should cause a problem i the name.
06-14-2011 06:15 AM
CJ,
move will not work since it does not accept a filename, only directory information. So you will not be able to rename any file using this function.
Norbert
06-14-2011 06:22 AM
Ok, great. That solves that issue then!
Is there another way that I can rename these CSV files rather than manually? I tried to use 'read spreadsheet' and then 'write spreadsheet' without manipulating the data in the files but the contents of the CSV were different and the file was much, much larger.
It seems like a pretty simple thing to do I just can't figure how to do it! Otherwise, i'm going to have to rename 300+ files!!! Eeek!
Thanks again,
CJ
06-14-2011 06:26 AM
CJ,
you can insert your "rename algorithm" in a loop and then building the filenames dynamically for each iteration.
hope this helps,
Norbert
06-14-2011 06:41 AM
Ok. So far i have been able to build the name i want but not rename the file or even make a duplicate with a different name. Is it possible for you to display an example of what your suggestion might look like?
Thanks,
CJ
06-14-2011 06:58 AM
CJ,
you might try something like this:
Norbert
PS: If this is hard to understand for you, you might want to do some online training or visit a LV course from NI.
06-14-2011 07:18 AM
Awesome! That worked a treat! I was close but had a few build path issues i think.
Also, i have done a Basics 1 & 2 course but as you may understand, the course does not cover everything!
Thanks again, Norbert.
CJ