File Name Checking

Discussion in 'Perl' started by Rich Bogle, Apr 22, 2004.

  1. Rich Bogle

    Rich Bogle Guest

    Does anyone have a good module or clean method for making sure file names do
    not have special charactes / illegal characters in them before attempting to
    save the file.

    I have a perl script that archives data based upon information in a text
    file in each directory. The archive location is derived from that location
    and I need to make sure there are no illegal / special characters in the
    file name before creating it.

    Thanks

    Rich
     
    Rich Bogle, Apr 22, 2004
    #1
    1. Advertising

  2. Rich Bogle

    Rich Bogle Guest

    Just thought that I should mention the email goes straight to a junk account
    so all replies should be posted in the group.
    Thanks.


    "Rich Bogle" <> wrote in message
    news:c68vrd$qld$...
    > Does anyone have a good module or clean method for making sure file names

    do
    > not have special charactes / illegal characters in them before attempting

    to
    > save the file.
    >
    > I have a perl script that archives data based upon information in a text
    > file in each directory. The archive location is derived from that

    location
    > and I need to make sure there are no illegal / special characters in the
    > file name before creating it.
    >
    > Thanks
    >
    > Rich
    >
    >
     
    Rich Bogle, Apr 22, 2004
    #2
    1. Advertising

  3. Rich Bogle

    Jim Gibson Guest

    In article <c68vrd$qld$>, Rich Bogle
    <> wrote:

    > Does anyone have a good module or clean method for making sure file names do
    > not have special charactes / illegal characters in them before attempting to
    > save the file.
    >
    > I have a perl script that archives data based upon information in a text
    > file in each directory. The archive location is derived from that location
    > and I need to make sure there are no illegal / special characters in the
    > file name before creating it.
    >
    > Thanks
    >
    > Rich
    >
    >


    Use the tr operator to replace every character except those you wish to
    keep. For example, if you only want the characters (a-zA-Z0-9_-.), use:

    $filename =~ tr/a-zA-Z0-9_-.//cd;

    For more info, enter "perldoc perlop" and search for 'Transliterates'.

    FYI: this newsgroup is defunct. Try comp.lang.perl.misc in the future.
     
    Jim Gibson, Apr 22, 2004
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?iso-8859-1?B?bW9vcJk=?=
    Replies:
    7
    Views:
    890
    Roedy Green
    Jan 2, 2006
  2. ding feng
    Replies:
    2
    Views:
    2,904
    ding feng
    Jun 25, 2003
  3. Bobby Chamness
    Replies:
    2
    Views:
    2,440
    Joe Smith
    Apr 22, 2007
  4. m
    Replies:
    2
    Views:
    412
  5. Jack-2
    Replies:
    3
    Views:
    327
    Jack-2
    Dec 24, 2003
Loading...

Share This Page