kncowans
(Getting the hang of it)
2002-07-17 10:51 PM
Distinguishing between a file and a directory

Hello all

I am starting a script to move some directories from one location on our server (Server 2000) to another and have run into a problem.

The following code returns the File Attributes incorrectly.

If I fill in the $Dir variable with a test directory that contains various files and directories the script does not seem to return the correct values.

Any suggestions?

code:
  

Break on

$Dir = "c:\testdir"

$File = Dir("$Dir")

While @Error = 0

$Attrib = GetFileAttr($File) & 16

? "Filename = '$File' Attribute = $Attrib"

?

$File = Dir()

Loop

All I need to do is to be able to distinguish a file from a directory.

I tested this section of the script on Windows XP Home and got the incorrect values.

Thanks in advance


Sealeopard
(KiX Master)
2002-07-18 04:06 AM
Re: Distinguishing between a file and a directory

What do you mean by incorrect value?
If GetFileAttrib($file) & 16 evaluates to '0' then it's a file, otherwise it's a directory. What values do you get?


Les
(KiX Master)
2002-07-18 04:37 AM
Re: Distinguishing between a file and a directory

See also, the FAQ

Topic: DIR() Primer


LonkeroAdministrator
(KiX Master Guru)
2002-07-18 07:56 AM
Re: Distinguishing between a file and a directory

it seems that line:
$Attrib = GetFileAttr($File) & 16

is your reason.
try with this:
$Attrib = GetFileAttr($Dir+"\"+$File) & 16


kncowans
(Getting the hang of it)
2002-07-18 10:41 AM
Re: Distinguishing between a file and a directory

Hello Lonkero

Thanks for that.

Its amazing how everything becomes clear when someone else points out the problem.

Bye for now

Kevin