Apple Event: May 7th at 7 am PT

Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Possible to write a script that verifies filenames?

Hello everyone,


I am currently in the process of building a nomenclature for all the different types of documents we handle at my office (people's inability to name things at least somewhat consistently being the cause), and while I am under the impression that there is no way of directly restricting filenames, I was hoping that someone could point me in the direction of writing a script that at least checks the general filename. Ideally, the goal is to have the job end in an email to the user and myself notifying both that the file they just tried to place on the server does not match naming criteria; we have a system set up in our company portal but that was written in PHP and I don't know of any way to translate that into applescript, bash, etc (syntax and protocols being different). Is this even a possibility or am I flirting with the impossible? Thanks to everyone for your time and assistance.

Posted on Feb 9, 2016 5:53 AM

Reply
6 replies

Feb 9, 2016 8:07 AM in response to Tony T1

Tony,


Thanks so much for your response! We had planned on doing a daily/hourly cron job to do the filechecks. I have a work-in-progress list of structures for filenames, and that's where the rub is. Character restrictions will definitely help, but I wonder if it's possible to do based on general naming conventions; for example, a fee schedule file would need to adhere to "Fee Schedule-'company name'-2016". Is it possible to validate the non-variable portions to ensure that the convention is adhered to?

Feb 9, 2016 8:18 AM in response to Outsider

That would be possible (I think), but will all the files require the preferred "Fee Schedule" at the start of the name?

What would need to be done is to loop through each file and test the names (i.e. check that there are no invalid char, check that the last 4 char are valid years, etc)


As a start, can you post a few examples of what's in the directory (incl both preferred and non-preferred names) and what you would like the filename convention to be.

Feb 9, 2016 11:25 AM in response to Outsider

You're basically rewriting what git or other version control software (or distributed version control software) might provide, or creating your own document management storage package, and you'll likely want to save the user's choice for the filename as metadata, and then generate your own filename in the document store. As you're clearly aware, users don't pick practical or predictable filenames, if given free choice.


As for some options and alternatives here, have a look around the 'net.


But sure, you can try enforcing a convention — but these conventions tend to increase over time, as you get document revisions, change control, access tracking, security requirements and the usual feature creep... Which is where starting out with and using a document management package, or maybe basing what you're doing on top of a distributed version control package might avoid some of the effort involved here.


Depending on what you're up to and how much effort you're planning to expend, storing the documents as blobs in a database might be reasonable here, and that also completely avoids dealing with filenames.

Possible to write a script that verifies filenames?

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.