1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

@filesize result for directory?

Discussion in 'Support' started by hwilkins, Feb 8, 2011.

  1. hwilkins

    Joined:
    May 27, 2008
    Messages:
    10
    Likes Received:
    0
    I have an alias that processes files versus directories differently that was originally written for 4NT v4 ... just seeing the light of day again.

    Back then, @FILESIZE returned -1 for directories, but it appears that today it returns 0 for them. No sweat -- things change.

    What is the most efficient way to tell if a string represents a file versus a directory?

    I am looking at possibly using @FOLDERS, as in:

    if %@folders["%i"\..] GT 0 [it's a folder, do folder stuff]
    if %@folders["%i"\..] EQ 0 [it's a file, do file stuff]

    Is there a better way?
     
  2. Steve Fabian

    Joined:
    May 20, 2008
    Messages:
    3,523
    Likes Received:
    4
    ---- Original Message ----
    From: hwilkins
    To: ESFabian@zenge.org
    Sent: Tuesday, 2011. February 8. 05:00
    Subject: [Support-t-2589] @filesize result for directory?

    | I have an alias that processes files versus directories differently
    | that was originally written for 4NT v4 ... just seeing the light of
    | day again.
    |
    | Back then, @FILESIZE returned -1 for directories, but it appears that
    | today it returns 0 for them. No sweat -- things change.
    |
    | What is the most efficient way to tell if a string represents a file
    | versus a directory?
    |
    | I am looking at possibly using @FOLDERS, as in:
    |
    | if %@folders["%i"\..] GT 0 [it's a folder, do folder stuff]
    | if %@folders["%i"\..] EQ 0 [it's a file, do file stuff]
    |
    | Is there a better way?

    Use the @ATTRIB function:

    switch %@attrib[filespec,D]
    case 0
    :: process as a file
    case 1
    :: process as a directory
    endswitch

    BTW, FOLDER is a more generic term than DIRECTORY - all directories are folders, but not all folders are directories (for example some are a collection of directories).
    --
    HTH, Steve
     
  3. samintz

    samintz Scott Mintz

    Joined:
    May 20, 2008
    Messages:
    1,177
    Likes Received:
    11
    How do you get the names in the first place?
    Is it your desire to process only files or to process everything
    in a tree and take different action based on whether it's a file or folder?

    You can use the ISDIR and/or ISFILE
    conditionals within an IFF or IF statement.

    help conditionalexpressions

    -Scott

    hwilkins <> wrote on 02/08/2011
    05:00:31 AM:



    day again.

     

Share This Page