Rename specific files using command prompt if exists
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
Hi Team,
How to rename few specific files dynamically in folder using command prompt?
Below is the scenario.
I've few set of files in Folder A. (AB_India_12345.xlsx, AB_China_4573.xlsx, XYZ_India_12345.xlsx, PQR_TYR_12345.csv)
The file rename should happen on 1st 2 files only since it has pattern of AB_*
The renamed should be AB_India.xlsx, AB_China.xlsx and the last 2 files should not change.
In a 2nd Scenario: Assume Folder A has only XYZ_India_12345.xlsx, PQR_TYR_12345.csv
So, here workflow should run fine and should not rename any file.
Solved! Go to Solution.
- Labels:
- Batch Macro
- Run Command
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
@Shaaz your first step should be to use a Directory tool. This will pull the list of all file in the folder of interest. You can also check the box for Include Subdirectories if you need to look through multiple folder levels for all files.
Then you will want to follow the Directory tool with a Filter tool. Configure the Filter tool with the Custom Filter option and use the expression Left([FileName], 3) = "AB_". This will only pass through the files that follow the AB_ pattern in the beginning of the file name.
Now that you have the specific files isolated, you want to use a Formula tool as the next step to extract exactly what you want from the file. You can use the following formula:
REGEX_Replace([FileName], "(.*_)(.*)_(.*)(\..*)", "$1$2$4")
This is looking for a specific pattern in the file using a regular expression to pull only the elements you need.
Then you create the desired command which is generally REN to rename the files.
After that you use a Summarize tool to collapse these commands into a single cell with newline delimiters.
Finally, you pass this to a Run Command tool to create a batch file and execute the command.
 
You can reference the Run Command tool configuration here: https://community.alteryx.com/t5/Alteryx-Designer-Desktop-Discussions/Copy-File-from-One-Folder-to-A...
My workflow is attached to this post.
