I have a folder with a lot of PDF files that I need to rename and order based upon the date in the file name. The files are named as follows and are either "Contractual" or "Drugs (Prescribing)" followed by the date "30Nov22" and the last two number "00" "01" "02", denote if there are multiple pdf's for that particular month. (Examples below).
Contractual30Nov2201
Contractual11Aug2201
Contractual31Aug2202
Drugs (Prescribing)09Sep2200
Drugs (Prescribing)10May2301
Drugs (Prescribing)11Jul2302
I am trying to get an output would allow me to have a file of PDFs that are in month and year order and split between contractual and drugs. So for the above examples the output would look something like
1. Contractual - Aug-22 - 1
2. Contractual - Aug-22 - 2
3. Contractual - Nov-22 - 1
4. Drugs - Sep-22 - 0
5. Drugs - May-23 - 1
6. Drugs - Jul-23 - 2
Any help would be much appreciated!
Solved! Go to Solution.
Hey @Chris1988, not sure whether this is a bit of overkill but here's something I've just built out that looks to achieve what you're after.
1) Use a Directory tool to point towards your file that contains the PDF files.
2) Bring a Blob Input tool onto the canvas which will allow you to bring your files into the workflow as objects.
3) Select is just removing excess fields/making life easier.
4) In a Formula tool we
- Flag Contractual vs. Drugs for the sake of ordering
- Parse the date from the filename, again for ordering
- Parse the order/index from the end of the filename, once more for ordering purposes
5) Sort on Contractual vs. Drugs flag (ascending), Date (ascending) and the monthly index (ascending) to get desired order
6) Use a RecordID to get the start of the new filename e.g. '6. Drugs'
7) Bring another Formula tool in to create the new FilePath
8) Use a Blob Output tool to output the objects (your PDFs) under their new names
When plugging into this workflow you'll need to repoint the Directory tool to wherever your PDFs are stored. I also created an 'Outputs' folder here when building mine that the new outputs go to. If you don't want that, just take it out of the final Formula expression - I have left a comment in there as well.
Hi @Chris1988
The attached workflow will do that for you.
BEFORE
AFTER
Reference: https://community.alteryx.com/t5/Community-Gallery/Rename-files/ta-p/998942
Hey @DataNath and @Felipe_Ribeir0 both solutions worked perfectly and were exactly what I wanted! Thanks for the help!