The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Win32::Filenames - The great new Win32::Filenames!

VERSION

Version 0.01

SYNOPSIS

This module can be used to validate if a given filename is a valid Windows filename and if it is not valid can fix the filename by replacing the invalid characters.

Perhaps a little code snippet.

    use Win32::Filenames qw(validate sanitize);
    
    my @filenames = ( 'file1.txt', '(file;;2.doc)', 'file::.doc?', 'file6',
                      'file7>>.txt' );
    my $test;
    foreach $test (@tests) {
      print "checking filename: [$test] ...";
      
      if ( validate($test) ) {
        print "Filename is ok.\n";
      }else{
        print "Filename is bad. **\n";
        print "\tTRY: ";
        print sanitize($test), "\n";
      }
    }

EXPORT

Nothing is exported by default.

The following are allowed to be exported:

  • sanitize() --> fix filename.

  • validate() --> check filename.

  • $ERR_CHAR --> what character was invalid in last filename check.

FUNCTIONS

validate($filename);

This function is passed a filename which is searched for any invalid characters. If there are no invalid characters then the function returns true. If the filename does contain invalid characters, the invalid character encountered is stored in the GLOBAL variable $ERR_CHAR and the function returns undef.

sanitize($filename, [ $replace_str ]);

This function is passed a filename to convert to a valid Windows filename. The function is also optionaly passed a string or character to be used to replace invalid characters with. If no replacement character is passed to the function, it defaults to use '-' to replace invalid characters.

If the replacement character passed to the function is itself an invalid character, then the function croaks. Otherwise, the filename is searched for any invalid characters, and string is returned with the invalid characters replaced.

AUTHOR

Brent Hostetler, <brent@the-hostetlers.net>

BUGS

Please report any bugs or feature requests to bug-win32-filenames@rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Win32-Filenames. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.

ACKNOWLEDGEMENTS

I would like to acknowledge myself! :P

COPYRIGHT & LICENSE

Copyright 2005 Brent Hostetler, All Rights Reserved.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.