This site uses different types of cookies, including analytics and functional cookies (its own and from other sites). To change your cookie settings or find out more, click here. If you continue browsing our website, you accept these cookies.
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):
I have a flat file (csv or excel) from my database that lists bibliographic details of publications with a system generated ID like so:
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.
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 ' & '.
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.
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.
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.