Creating a customer folder

I need to create a folder based on the user input, capitalise it, check for matches and then check for a unique code.

If the name begins with ‘The’ then that needs to be removed and added to the end I.e. the abc company will end up Abc Company, The.

I then need to check if the name exists in the folder, if it does I need to let the user know and stop. If it doesn’t exist then I can continue and create the folder.

Finally, I need to create a unique customer code which takes the first 4 characters of the name and adds a number I.e. 01. If that 4 digit code already exists then I need to increase the number by +1.

i.e the abc company will end up Abc Company, The (ABCC01)

Now if the user adds another company called: the abc characters, this would end up ABC Characters, The (ABCC02)

This is because the 4 digit code ABCC will have already existed.

Last but not least, if the final 6 digit code gets to 10 i.e. ABCC10, I won’t need the 0 that has sat in front of the number 1-9

I need a little help getting over the line. Here’s what I have so far Shortcuts

The issues are, if there is no folder in the main folder, it won’t work and an error comes up. I have created an alert to show this for the moment. Now if the main folder has 1 folder in it, I get an error. If the main folder has 2 folders in it it works. I’ve not even begun trying to match the name or code yet.

I had a little bit of time so here you go. Hope the comments makes it easy enough to understand.

https://www.icloud.com/shortcuts/ae45683d59cb4b5d8de3610f496a37d1

Thank you. It doesn’t quite work 100% but I think I can finish it off now thanks to your help.

Thanks

Hi,

The issue with the code is that when you add multiple clients that have a similar name i.e. The ABC Company, The ABC Chunga, The ABC CatHouses. The 4digit code i.e. ABCC should be adding +1 everytime it finds a match for that code.

Currently it it adds the code ABCC01, ABCC02, ABCC01, ABCC01 where as it should be ABCC01, ABCC02, ABCC03, ABCC04 etc

I’ve been trying to break apart the code but I can’t work out that part. If you have a minute, can you have a look please.

I’m sure it’s todo with this line: const nextNumber = 00${matchingFolders.length + 1}.slice(-2) clientFolder = ${clientName} (${fourDigitCode}${nextNumber})``

Thanks

The issue is with this line

folder = input.folderContents

it should have been

folderContents = input.folderContents

Thank you. That works perfectly. Now onto my next two shortcut. Create project folders and then batch rename folder, hopefully I can figure these ones out n my own now.

Thank you.