Join the Alteryx Community’s Maveryx Summer Cup event! Compete, network with others, and earn your gold through a series of challenges from July 24th to August 11th. Learn more about the event here.

Alteryx Designer Desktop Discussions

Find answers, ask questions, and share expertise about Alteryx Designer Desktop and Intelligence Suite.

Rename .txt files - need help

mikedesena
7 - Meteor

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?

mikedesena_0-1681497263838.png

 

2 REPLIES 2
RobertOdera
13 - Pulsar

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!

SPetrie
13 - Pulsar

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.

SPetrie_1-1681503787952.png

 

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.

SPetrie_2-1681503959469.png

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) 

SPetrie_3-1681504089727.png

 

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. 

SPetrie_4-1681504223321.png

SPetrie_5-1681504342951.png

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.

SPetrie_6-1681504674463.png

 

 

Labels