community
cancel
Showing results for 
Search instead for 
Did you mean: 

Alteryx designer Discussions

Find answers, ask questions, and share expertise about Alteryx Designer.
Upgrade Alteryx Designer in 10 Steps

Debating whether or not to upgrade to the latest version of Alteryx Designer?

LEARN MORE

Changing multiple file names in a directory

Meteor

How can I change the file name of multiple files at one time? They all currently have different names and I want to change them so that each one will have a different name with the same number (year) on the end.

Alteryx Partner

Are you trying to write multiple files and have each one with a different name with the same year number, or you're just trying to change the names of files in a directory on your computer?

 

If you're trying to write multiple files, you can add a field with the name you'd like to all records to be written in that file, and then select the "Take File/Table Name From Field" configuration at the bottom, and select "Change File/Table Name" from the drop down menu.

 

In order to get the same year number in each one, you could create this "file_name" field using a formula.

 

I can go a little more in depth if you need once you let me know a little more about the problem.

 

Cheers!

 

Meteor

I am reorganizing several thousand files that are located in folders by year and then by month. I have a batch macro that is copying the files from the archived folder into a new location. I'd like to change the names of the files after I've copied them over to the new folder. Each subfolder has the same/similar file names so when copying them over I'd like to identify them by the month/year they came from. For example if a file came from the January folder and the 2001 subfolder and was called "apple" I'd like to change the name to "APPLE 01_01"

 

Thanks!

Kelly

Alteryx Partner

So it sounds like you're reading in each of the files, then outputting them to the new folder. In this case, the approach I mentioned above should work, provided you can find a way to create this new file.

 

Is it possible for you to provide a screenshot of your batch macro? It would make it easier to identify the best way to do this.

 

What is your batch macro's Grouping Field? Do you have year/month information in the records contained within the files?

 

If you're using the Directory tool to read in all these files in each folder, you could perhaps take the file name from there, and add the year/month information from the file, or if your batch macro groups on year/month, you could perhaps try and get it from there.

 

In general, you'll want to add a formula tool creating a field called "file_name" with an expression like:

 

[original_filename] + "_" +  [Month] + "_" + [ Year]

 

With a little more information about the information your batch macro has available to it, I could probably help work this out a little more precisely if you needed.

Meteor

Yes I am changing the file type and outputting to a different folder. I don't have a Grouping Field. I'm not sure where this is located. The year/month is not located in the folders. I am using the directory tool with the macro attached to pull the files and output to a specific folder (which I have just been changing the directory input and the output in the macro).

 

I've attached a screenshot of my batch macro.

Alteryx Partner

The Grouping Field would be the field passed to the control parameter input of a Macro, it seems like yours would be the "full path" input from the Directory Tool.

 

In this case, I think your best course of action would be to do some RegEx parsing in order to pull out the year and month from the full path that you're passing to the macro.

 

I've attached a sample workflow, and here's a screenshot below:

 

Spoiler
batchrename.PNG

You could also add in a step of logic which would convert the month names into numbers if you desired instead of using the raw month string.

 

Without an idea about the directory structure it will be hard for me to develop a RegEx to parse it properly, I recommend using RegEx101 to do some testing and figure out exactly how you want to do this. You'll want to find a way to immediately remove the whole "C:/Users/User/Documents".... or whatever, until you're left with a string similar to my "Field1" in the workflow, with only the information you want (year, month, filename). You could do so with a RegEx Tool set to "Replace", where you look for the year, and replace everything before it with "", a blank string. If you need me to clear up what the RegEx I've used here is doing just let me know.

 

Cheers!

Labels