|
|||
|
Who is this for What you need to know
Introduction On a Linux/Unix machine, you can do a stat in Perl and check for the directory bit in the file mode item returned from stat. But this is Windows so stat does not return any information on whether the name is a directory or a file. What did I do? Option 1: The Quick Way
open (POOL,
"dir $pool |") || die "Cannot open $pool\n"; if ($pool =~ m/<DIR>/gi) { processDir() } }
This is the simplest way because it uses the DIR command in DOS and determines if the name is a directory or not based on the string <DIR> that is displayed by the command. Option 2: The Cleaner Way The cleaner way is to use the Win32::File module. This module has two methods: GetAttributes and SetAttributes. It also has several constants that you can use to determine the attributes of a given file. The format of the commands are: GetAttributes($filename, $resultattr); SetAttributes($filename, $attrtoset); Each bit of the resulting byte ($resultattr) from GetAttributes identifies an attribute. To determine the attribute of a file, you need to check if the bit is a 1. You can use these constants to simplify things for you. This is a sample routine to show how this works: Go To Page: 1 2
The copyright of the article Getting Windows File Attributes in Perl is owned by . Permission to republish Getting Windows File Attributes in print or online must be granted by the author in writing.
For a complete listing of article comments, questions, and other discussions related to Philip Yuson's Perl topic, please visit the Discussions page. |
|||
|
|
|||
|
|
|||