File::Spec::Win32(3pm)

✨ File::Spec::Win32 β€” methods for Win32 file specs ✨

Okay bestie, so this is the File::Spec::Win32 page from the Perl Programmers Reference Guide, and it's basically the Windows-flavoured version of the whole File::Spec situation. Let's get into it πŸ’…


πŸŽ€ SYNOPSIS πŸŽ€

require File::Spec::Win32; # Done internally by File::Spec if needed

That's it, that's the whole synopsis. You basically never load this yourself β€” File::Spec pulls it in for you if it needs it, iykyk. 🫢


🌸 DESCRIPTION 🌸

So here's the tea: for documentation on all the methods this thing provides, go read File::Spec::Unix. This package overrides the implementation of those methods, not the semantics β€” meaning the vibes stay the same, only the code underneath changes. πŸ’–

Now, method by method:

πŸ¦‹ devnull

Returns a string representation of the null device. That's it. That's the whole method. Iconic, honestly. ✨

πŸ“ tmpdir

Returns a string representation of the first existing directory from this list, in this exact order:

$ENV{TMPDIR}
$ENV{TEMP}
$ENV{TMP}
SYS:/temp
C:\system\temp
C:/temp
/tmp
/

Lowkey important detail: SYS:/temp is the preferred one in Novell NetWare, and C:\system\temp is the one for Symbian β€” because File::Spec::Win32 is used for those platforms too, not just Windows. 🫢

⚠️ And if you're running under taint mode, and those environment variables are tainted, they are not used. Safety first, bestie. πŸ”₯

🧚 case_tolerant

On MSWin32, case-tolerance depends on GetVolumeInformation() $ouFsFlags == FS_CASE_SENSITIVE, which is the thing that indicates case significance when comparing file specifications. Since XP, FS_CASE_SENSITIVE is effectively disabled for the NT subsubsystem.

The original points you at http://cygwin.com/ml/cygwin/2007-07/msg00891.html if you want the lore. πŸ’€

Default: 1

πŸ‘‘ file_name_is_absolute

As of right now (yes, really, "as of right now"), this returns:

  • 2 if the path is absolute with a volume
  • 1 if it's absolute with no volume
  • 0 otherwise

Three whole states, main character energy. 🌈

⭐ catfile

Concatenates one or more directory names and a filename to form a complete path ending with a filename. A little path-building slay. πŸ’…

πŸŽ€ canonpath

No physical check on the filesystem β€” this is a logical cleanup of a path only. Do not expect it to go touch grass and verify anything actually exists. πŸ™ˆ

On UNIX it eliminates successive slashes and successive "/.". On Win32 it makes this happen:

dir1\dir2\dir3\..\..\dir4 -> \dir\dir4 and even
dir1\dir2\dir3\...\dir4   -> \dir\dir4

Yes, even the ... one. We love a flexible icon. πŸ¦‹

πŸ’œ splitpath

($volume,$directories,$file) = File::Spec->splitpath( $path );
($volume,$directories,$file) = File::Spec->splitpath( $path,
                                                      $no_file );

Splits a path into its volume, directory, and filename portions. It assumes the last thing is a file path unless the path ends in '\\', '\\.', '\\..', or $no_file is true. On Win32 that means a true $no_file makes this return ( $volume, $path, '' ). 🫢

Separators accepted are \ and /.

Volumes can be drive letters or UNC sharenames (\\server\share).

And the results can be passed to "catpath" to get back a path equivalent to (usually identical to) the original path. Round trip, bestie. ✨

🐚 splitdir

The opposite of catdir(). Literally the reverse vibe.

@dirs = File::Spec->splitdir( $directories );

Heads up: $directories must be only the directory portion of the path on systems that have the concept of a volume, or that have path syntax that differentiates files from directories. No sneaking filenames in there. πŸ’€

And unlike just splitting the directories on the separator, leading empty and trailing directory entries can be returned, because these are significant on some OSs. So this:

File::Spec->splitdir( "/a/b//c/" );

Yields exactly this:

( '', 'a', 'b', '', 'c', '' )

Look at those empty strings. They're supposed to be there. Not a bug. πŸŽ€

🌸 catpath

Takes volume, directory and file portions and returns an entire path. Under Unix, $volume is ignored and this is just like catfile(). On other OSs, the $volume becomes significant. πŸ‘‘


🧚 Note For File::Spec::Win32 Maintainers 🧚

Novell NetWare inherits its File::Spec behaviour from File::Spec::Win32. That's the whole note. Protect this knowledge. πŸ”₯


Copyright (c) 2004,2007 by the Perl 5 Porters. All rights reserved.

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


🌈 SEE ALSO 🌈

See File::Spec and File::Spec::Unix. And remember the whole point: this package overrides the implementation of these methods, not the semantics. Same energy, different engine. πŸ’–


That's the whole page, bestie β€” no cap, every single flag and path and default is in there. Slay. πŸ’…

πŸ’– Signing off from perl v5.42.3, dated 2026-11-03 β€” see you in the next manpage, mwah 🫢✨

πŸ“¦ where this page comes from