Advent of Code is back! Unwrap daily challenges to sharpen your Alteryx skills and earn badges along the way! Learn more now.

Alteryx Designer Desktop Discussions

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

How to replace an existing file and rename it dynamically

nazuk
8 - Asteroid

Hello All,

 

So here i having 4 files in a directory. So one of the file name is Outstanding_TSE082QT_07-06-2020_4565. So i am following a business rules to prepare a data . So the final output needs to be overwrite in Outstanding_TSE082QT_07-06-2020_4565 where 07-06-2020_4565 need to be replaced by today's date,month,year and time. 

 

I have attached my simplified task.

 

Please suggest.

 
 
 
 
 

 

14 REPLIES 14
DavidP
17 - Castor
17 - Castor

If you are using a field such as [filename] to dynamically change the filename and sheetname of a file, use the option Change entire file path.

 

Of course, you have to then include the whole path in [filename].

DavidP
17 - Castor
17 - Castor

You could also bring through the fullpath from the Input Data tool and use a formula tool to replace the date part of it, as shown:

 

DavidP_0-1586267930119.png

 

This process doesn't rename the file, it creates a new file with a new name. The old file will still be there. It you want to actually rename the file, you'll have to use the Run Command Tool to execute a DOS command.

nazuk
8 - Asteroid

So we can't replace an existing file having the same keyword(the static part in the file name)?

DavidP
17 - Castor
17 - Castor

It will only replace the file if you overwrite it using exactly the same filename, but since you're changing the filename by inserting the current data, a new file will be created and the old one will still be there.

nazuk
8 - Asteroid

Understood. Thanks.

 

By the way, can i check with you that only the latest file should be kept, deleting the old file? 

DavidP
17 - Castor
17 - Castor

This is how you can delete the original file

 

DavidP_0-1586271553952.png

 

DavidP
17 - Castor
17 - Castor

Another, perhaps simpler, way of doing it is to do it all in DOS and not use Input and Output Data tools at all, like this:

 

DavidP_0-1586273188586.png

 

nazuk
8 - Asteroid

Sorry for the question(might be a silly one). But i am a beginner in Aletryx. Got my first assignment, so just exploring and asking questions.

 

So basically i am already inputting that file. So again when i will connect the same node to an output and to an Dos command. How alteryx will analyze, that first it has to write those records in a new file and then run it.

 

 

DavidP
17 - Castor
17 - Castor

So, then you can stick with the 1st suggestion.

 

It doesn't really matter if the new file is written before the old one is deleted, as long as the data is loaded by the input data tool. Once the data is in the workflow, it will be written to the new file unless there is an error in the workflow that prevents it from completing.

Labels