grab an account number from a filename

Hi
Im trying to grab a number from a filename and insert it into a txt.
Have no idea if this can be done.

Im explaining it better.

  1. I have 2 folders. Accounts and byNumber
  2. I have to check if there is any file with similar name in the 2 folders. By similar I mean Account->[5534]john_denver.txt and byNumber-> john_denver.txt
  3. if there is such a file I have to write inside john_denver.txt the number that is in the brackets: 5534.
  4. I have to write this number in a specific point like “account_number: 5534”.

Numbers can vary in length.

Thanks

Yes, it can.

You can help yourself getting started by reading the material provided in the Unscripted section, specifically these 2 articles:
Using AppleScript’s Text Item Delimiters, which will show you how to isolate that account number, and
The Ins & Outs of File Read/Write in AppleScript, where you will be shown how to write it to a text file.