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

Renaming files at system level

RPS
7 - Meteor

Hi All,

 

I am a relatively new starter and I have a question about renaming files in a directory.  I have searched the community boards and came across a similar question but it didn't look to be resolved, an so my post.  Issue described below:

 

I have a directory with pdf documents that look like this (these are published journal articles):

A.pdf

B.pdf

C.pdf

 

I have a flat file (csv or excel) from my database that lists bibliographic details of publications with a system generated ID like so:

Ax1

Bx2

Cx3

 

A, B & C correspond, so now I want to rename my pdf files (in my directory) with the system IDs in the format <system ID.pdf>

 

Is there a way to automate this in Alteryx? Can files be physically renamed at the system level?

 

I have done a basic workflow using the above two as inputs where I have name matched but that is as far as I got.  I don't know how to rename.  

 

Any help will be greatly appreciated.

13 REPLIES 13
DavidP
17 - Castor
17 - Castor
You can use alteryx to create a DOS command to execute with the Run batch tool. I’ll send you an example ASAP
RPS
7 - Meteor

That"s great, thanks David.  I'll wait for your solution.  Greatly appreciated.

DavidP
17 - Castor
17 - Castor

Ok, here you go. In the example below, the Text Input represent your ID's Ax1, Bx2 and Cx3. The directory tool reads the list of filenames from a folder.  

 

You need to find a mapping between the ID's and the filenames - for simplicity I just took the 1st letter of the ID as my JoinID and the filename minus .pdf. You then use a join tool to map the 2 so that you can get the old filename and the new filename in the same record.

 

I then have enough to build the command line string [cmd]. Experience taught me to always test the [cmd] string in a DOS window to make sure that it works and that the syntax is correct. 

 

Once you're happy that it does what you want, you can tell the Run Batch Tool to execute it.

 

Sample workflow attached - I'd encourage you to play around with it.

 

You can have more than 1 DOS command in the same string, just separate them with ' & '.

 

Let me know if you need any more help. 

 

rename files.png

RPS
7 - Meteor

Thanks David.  It is 12am here and i'm falling asleep :).

 

I'll check it first thing tomorrow morning and get back to you with questions (if any).  I'll let you know how it goes.

 

Thanks for your help.

 

Cheers!

RPS
7 - Meteor

Hi David,

 

Awfully sorry for the tardy response.  This problem turned out to be bigger than ben hur and I had to re-engineer your entire workflow.  Also I don't think that I had articulated the problem well in the first instance.  I have now managed to get the cmd string but stuck at the Run tool.

Capture2.PNG

 

 

Capture.PNG

 

Do I need to save the command as a batch file?  If so, how do I do that?  I think that I am very close to the end if I can only get a fix on the Run command.

 

Many thanks for your help so far, it is greatly appreciated.

DavidP
17 - Castor
17 - Castor

Here's how I have the Run Command Tool configured in the workflow I attached in my first post. You should actually be able to just copy and paste the Run Command Tool from my workflow to yours. Just change your command line field name from [Cmd] to [cmd] and make sure that all other fields are removed with a select tool so that the data connection to the Run Command Tool only contains the [cmd] field.

 

It essentially creates the batch file, CopyTemplate.bat, containing the text that's in the [cmd] field in the temp folder and then executes it.

 

I remember it took a little bit of playing around with it initially to get it working, which is why I now just copy the configured tool into my new workflow and update the [cmd] string to what I want it to do.

 

 

run command 2.png

DavidP
17 - Castor
17 - Castor

Also, you probably want to reduce the number of Browse tools in your workflow as it will impact performance at runtime.

RPS
7 - Meteor

That worked like magic, thank you.  As you suggested, I simply copy-pasted your run command and it worked a treat.  This opens up a world of possibilities.

Thanks a bunch for your help.

Cheers!

RPS
7 - Meteor

I will certainly remove the browse tools from the workflow now.  I keep them on as I am an early stage user of Alteryx and the browse tools are my sanity check, but I get your point about performance.

 

Labels