Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Greetings Perly Monks! I have (what I hope is) an easy question: Is there a way to force readdir to return short file names in Windows? For example: "Docume~1" instead of "Documents and Settings" Many thanks for your help! -Seeker of Knowledge

Replies are listed 'Best First'.
Re: readdir and short file names
by davidrw (Prior) on May 11, 2005 at 20:35 UTC
    I think the Win32::GetShortPathName(PATHNAME) method in Win32 should get you the info you need.
Re: readdir and short file names
by ikegami (Patriarch) on May 11, 2005 at 20:45 UTC
    while (defined($long_file_name = readdir(DIR))) { my $short_path = Win32::GetShortPathName("$dir\\$long_file_name"); (my $short_file_name = $short_path) =~ s#^.*[\\/]##; ... }

    For fun,

    $dir = ...; @files = map { (split(' ', substr($_, 39)))[0] } split("\n", `dir /x "$dir"`);

    will also do the trick.