Outsider

Q: 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

Close

Q: Possible to write a script that verifies filenames?

  • All replies
  • Helpful answers

  • by Tony T1,

    Tony T1 Tony T1 Feb 9, 2016 7:28 AM in response to Outsider
    Level 6 (9,232 points)
    Mac OS X
    Feb 9, 2016 7:28 AM in response to Outsider

    Are you going to do a check of the files in the directory (daily, hourly, etc)?

    If so, then it's possible to check if a filename has a character you do not want used (i.e. filename#3.txt)

    Do you have a list of the characters you do not want used that you can post here?

  • by Outsider,

    Outsider Outsider Feb 9, 2016 8:07 AM in response to Tony T1
    Level 1 (115 points)
    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?

  • by Tony T1,

    Tony T1 Tony T1 Feb 9, 2016 8:18 AM in response to Outsider
    Level 6 (9,232 points)
    Mac OS X
    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.

  • by Outsider,

    Outsider Outsider Feb 9, 2016 8:19 AM in response to Tony T1
    Level 1 (115 points)
    Feb 9, 2016 8:19 AM in response to Tony T1

    Tony,

     

    Again, thank you beyond words. I've got a meeting in a few minutes but will be able to provide a bit more this afternoon.

  • by Tony T1,

    Tony T1 Tony T1 Feb 9, 2016 8:34 AM in response to Outsider
    Level 6 (9,232 points)
    Mac OS X
    Feb 9, 2016 8:34 AM in response to Outsider

    Start with some easy checks and then we can adapt to more complex checks as we progress (and I'm sure others more adept than myself will help when given some samples to work with)

  • by MrHoffman,

    MrHoffman MrHoffman Feb 9, 2016 11:25 AM in response to Outsider
    Level 6 (15,612 points)
    Mac OS X
    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.