Script To Auto Generate Numbers As A Text file name

I have tried to make a script that will look in a folder for a new text file and generate a 9 digit number I am trying make the script do the following.

1.) I need this script to trigger whenever a text file has been Added or Modified in a folder named: 000.WFR (I name my folders to start with 3 Zero’s as shown).

2.) The script will rename the New Text File to a 9 digit number separated by a period (.) like so… ex. 00000.0000 (the period must be after the 5th digit as shown)

3). The script will place the new generated number inside the text file next to text that already exist. This text will have a colon at the end, unless it needs to be removed in order for the script to work correctly. ex. AccountNumber: 00000.0000

4.) The script will duplicate the text file then make a folder named the number it just generated in a folder called: 000.WorkflowClientID and will place the folder with text file there.

5.) If the script is triggered by a Modified file, then the script will place the modified file to it’s respective folder in the folder named 000.WorkflowClientId

recap:

  1. Script Looks In Folder - 000.WFR

  2. Script names the new text file to a 9 digit number - 00000.0000

  3. script will place the generated number inside the text file next to text that already exist: AccountNumber:

  4. Script makes a New folder with the same name as the text file and with the text file in a Folder named - 000.WorkflowClientID

  5. Script will continue to auto generate the numbers by remembering the last number generated in increments of 1 as long as there is a New text file added to the folder that is named: 000.WFR. ex. 00000.0001 00000.0002 00000.0004 etc.

  6. Script looks for any Modified Text File(s) in the 000.WFR folder and places the Modified Text File in the folder named: 000.WorkflowClientId and to the correct folder that has the same name as the text file.

I greatly appreciate any help on this! I hope it all made sense! Thanx Charlie!