View on
MetaCPAN is shutting down
For details read Perl NOC. After June 25th this page will redirect to
Brent Hostetler > Win32-Filenames-0.01 > Win32::Filenames



Annotate this POD


New  3
Open  1
View/Report Bugs
Module Version: 0.01   Source  


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


Version 0.01


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";
        print "Filename is bad. **\n";
        print "\tTRY: ";
        print sanitize($test), "\n";


Nothing is exported by default.

The following are allowed to be exported:



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.


Brent Hostetler, <>


Please report any bugs or feature requests to, or through the web interface at I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.


I would like to acknowledge myself! :P


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.

syntax highlighting: