I am trying to rename about 50 text files every month after a data pull. I have seen this posted a lot but I get lost on the execution. Most solutions use the Run Command but seems out of my current level.
The steps I have are in an image here. I want to rename the old "FileName" to be "FileName_New". Can anyone out there help me?
Hi, @mikedesena
Kindly consider this post: Solved: Re: How to replace an existing file and rename it ... - Alteryx Community
But also, are you trying to rename the Field or the Field Value or both? Cheers!
Assuming we are using a batch file and cmd, the format for a rename is
ren [<drive>:][<path>]<filename1> <filename2>
We need to get your existing filename and the new file name into that format before saving the commands to a batch file.
Also, since you are doing it inside alteryx after opening the files, you will want to summarize the rename commands so you only have one rename per file.
I mocked up some data based on your screenshot for this example.
The [<drive>:][<path>]<filename1> part of the format is easy, thats the full path you already have as FileName
Since the new file name is basically the old file name but with info added to the front and end, you can use the FileGetFileName formula and the FileGetExt formula.
FileGetFileName gives us "File01" in this example
FileGetExt gives us ".Txt"
ToString([Field_12])+"_"+FileGetFileName([Filename])+"_New"+FileGetExt([Filename])
Next, join the parts of the formula together and encapsulate them with quotes to account for spaces in the file path (cmd doesnt like those)
Summarize the command and that result is what you feed to your run tool
Use the temp folder so the batch doesnt stick around and make it a csv type file that has not delineators.
The only other item I like to add to these is a final command of exit /B to terminate the script.
Alteryx generates errors after some scripts and adding that helps prevent them.