Announcement

Collapse
No announcement yet.

Isfile 9.02

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Isfile 9.02

    ISFILE now (in 9.02) only supports files and not directories.

    Now I need ISFILEORDIR. Or did I miss something?

  • #2
    What's wrong with Dir$

    Comment


    • #3
      am I confused or does DIR$ not tell you if a file or directory exists ?

      N.

      Comment


      • #4
        SNAP Carlo

        Comment


        • #5
          Attention - there are actually different.

          It is not simply an unordered list of valid and invalid
          file and folder names to filter.

          Sample:
          ISFILE("C:\pagefile.sys") = true
          DIR$("C:\pagefile.sys") = ""
          GETATTR("C:\pagefile.sys") >>> error = "Permisson denied"

          Comment


          • #6
            ???
            Code:
            DIR$ (spec, ONLY %SUBDIR) 'dirs only
            DIR$ (spec, %SUBDIR)                   'dirs and files
            DIR$ (spec)                                '  files only
            ???
            Michael Mattias
            Tal Systems (retired)
            Port Washington WI USA
            [email protected]
            http://www.talsystems.com

            Comment


            • #7
              Here is a quick example of DIR$ which snapshots the WINDOWS first level of sub-directories, with uninstall directories omitted, but all others listed.
              Code:
              #COMPILE EXE
              #DIM ALL
              
              FUNCTION PBMAIN () AS LONG
                  DIM temp$,msg$
                  temp$ = DIR$("C:\WINDOWS\*.",ONLY %SUBDIR OR %SYSTEM OR %HIDDEN)
                  WHILE LEN(temp$)
                    'omit XP $...Uninstall.... directories for listing
                    IF LEFT$(temp$,1) <> "$" THEN msg$ = BUILD$(msg$,$CRLF,temp$)
                    temp$ = DIR$(NEXT)
                  WEND
                  ? msg$
              END FUNCTION
              Rick Angell

              Comment


              • #8
                and for those that can't wait ... MACROS rule!

                Code:
                MACRO FUNCTION IsDirectory(Dirname)
                    MACROTEMP result
                    DIM result AS LONG
                    IF DIR$(Dirname, ONLY %SUBDIR OR %SYSTEM OR %HIDDEN) <> "" THEN result = -1
                    IF INSTR(Dirname,ANY "*?") THEN result = 0  'no wildcards like IsFile operation
                END MACRO = result
                Caveat: Dirname$ is an unambiguous directory name, which may not contain an asterisk (*) or query (?). Same as IsFilename restrictions
                Last edited by Richard Angell; 9 Oct 2009, 11:43 AM. Reason: changed macro name to be a more explicit
                Rick Angell

                Comment


                • #9
                  The results returned by IsFile were not always well defined in previous versions. After examining how the function is generally used in practice, the design was changed to do as the name suggests-- tell you whether a specific file exists. If you need to check for a folder instead, you might try DIR$ (and consider the ONLY option).
                  Sincerely,

                  Steve Rossell
                  PowerBASIC Staff

                  Comment


                  • #10
                    The results returned by IsFile were not always well defined in previous versions
                    Say What?

                    You don't think you guys would have heard from me had 'observed behavior' varied from 'actual behavior?' This is one place where the documented capabilities are "dead on."

                    Sounds like the Microsoft Touch (aka "we know better") is entrenching itself even deeper in the bowels of the PowerBASIC product line....

                    What's next, you are going to drop PowerTree(tm) because it's just too hard to understand what an 'index' is?

                    Puh..leeze!


                    MCM
                    Michael Mattias
                    Tal Systems (retired)
                    Port Washington WI USA
                    [email protected]
                    http://www.talsystems.com

                    Comment


                    • #11
                      Ah, Michael. When you have no idea what you're talking about, perhaps you should not volunteer such opinions.

                      Comment


                      • #12
                        Code:
                        MACRO FUNCTION IsDirectory(Dirname)
                            MACROTEMP result
                            DIM result AS LONG
                            IF DIR$(Dirname, ONLY %SUBDIR OR %SYSTEM OR %HIDDEN) <> "" THEN result = -1
                            IF INSTR(Dirname,ANY "*?") THEN result = 0  'no wildcards like IsFile operation
                        END MACRO = result
                        With another caveat!

                        Code:
                        ONLY %SUBDIR OR %SYSTEM OR %HIDDEN
                        will return TRUE if tested on a hidden or system file, as well as a directory.

                        Testing results on Windows XP:
                        Code:
                        ' Equate patterns:
                        ' alpha:    ONLY %SUBDIR
                        ' beta:     ONLY %SUBDIR OR %SYSTEM OR %HIDDEN
                        
                        
                        ' Equate    Attributes      Example                    Result    Expected
                        ' ------    ----------      -------                    ------    --------
                        ' alpha     Dir             C:\Windows                 T         yes
                        ' alpha     Dir, Hidden     C:\Windows\Installer       F         yes
                        ' alpha     File            C:\WINDOWS\winhlp32.exe    F         yes
                        ' alpha     File, Hidden    C:\WINDOWS\winnt.bmp       F         yes
                        
                        ' beta      Dir             C:\Windows                 T         yes
                        ' beta      Dir, Hidden     C:\Windows\Installer       T         yes
                        ' beta      File            C:\WINDOWS\winhlp32.exe    F         yes
                        ' beta      File, Hidden    C:\WINDOWS\winnt.bmp       T         no
                        Here is an alternative:
                        Code:
                        #If Not %def(%TRUE)
                            ' win32api.inc not included
                            %TRUE = -1
                        #EndIf
                        
                        Function IsDirectory(rsPath As String) As Long
                        ' Purpose:      test if a directory exists (not a volume)
                        ' Parameters:   rsPath - directory name to test. invalid if empty or has wildcards. works with or without a trailing slash
                        ' Returns:      T: directory exists; F: otherwise
                        ' Note:         "Only %SUBDIR Or %SYSTEM Or %HIDDEN" will return T for a hidden or system file
                            Local lRtn As Long
                        
                            If (Len(rsPath) > 0) And (IsFalse InStr(rsPath, Any "*?")) Then
                                If Len(Dir$(rsPath, Only %SUBDIR)) > 0 Then
                                    ' directory, not hidden or system
                                    lRtn = %TRUE
                                Else
                                    ' test for hidden or system directory
                                    If IsFalse IsFile(rsPath) Then
                                        ' not a file
                                        If Len(Dir$(rsPath, Only %SUBDIR Or %SYSTEM Or %HIDDEN)) > 0 Then
                                            ' directory, hidden or system
                                            lRtn = %TRUE
                                        End If
                                    End If
                                End If
                            End If
                        'IsDirectory_Exit:
                            Function = lRtn
                        End Function

                        Comment


                        • #13
                          What is the operator precedence for ONLY?

                          ORIGINAL: ONLY %SUBDIR OR %SYSTEM OR %HIDDEN

                          Does this mean
                          ONLY ( %SUBDIR OR %SYSTEM OR %HIDDEN) ?
                          ( return only system, hidden subdirs)

                          Or does it mean
                          (ONLY %SUBDIR) OR %SYSTEM OR %HIDDEN ?
                          return all subdirs, plus files if they are hidden or system

                          So back to question one: What is the operator precedence for ONLY?

                          MCM
                          Michael Mattias
                          Tal Systems (retired)
                          Port Washington WI USA
                          [email protected]
                          http://www.talsystems.com

                          Comment


                          • #14
                            When you have no idea what you're talking about, perhaps you should not volunteer such opinions.
                            As long as such things are allowed here I shall volunteer my opinions whenever I bleep well please.

                            BTW, please check the forum rules. I think you are dangerously close to personal imprecation, which is NOT permitted here.
                            Michael Mattias
                            Tal Systems (retired)
                            Port Washington WI USA
                            [email protected]
                            http://www.talsystems.com

                            Comment


                            • #15
                              Michael, you explicitly stated that you didn't know of any problem with IsFile. Then you complained about how we fixed the problem, without knowing what the problem was. Now you want to claim a case of personal abuse because I brought this up? That tune is not going to play in Peoria.

                              The OR operator is not sensitive to precedence:

                              (A OR B) OR C = A OR (B OR C)

                              Comment


                              • #16
                                The opinion I expressed had little or nothing to do with the ISFILE function itself. I did not complain you had FIXED it, I complained you CHANGED it.

                                The operator precedence question was not about OR, it was about ONLY

                                "PowerBASIC listens," sure; but does it read?

                                MCM
                                Michael Mattias
                                Tal Systems (retired)
                                Port Washington WI USA
                                [email protected]
                                http://www.talsystems.com

                                Comment


                                • #17
                                  Hello Community!

                                  I made the following experience using IsFile().
                                  Since PBWin 9 I'm using IsFile() for finding and loading files into my application.
                                  The application is protected by ExeCrypt.
                                  Everything works fine with IsFile() -
                                  since yesterday when I downloaded PBWin 9.02.
                                  I'did not change any code: I only recompiled using PBWin 9.02.
                                  After reprotection with EXeCrypt (I havn't changed this) I got problems in
                                  finding files.
                                  The filenames I'm working with use an underscore like
                                  "myFile_V5.dat" (Ok: the ending "dat" is another problem...)
                                  When I changed the code to DIR$ everything works reliable again.
                                  I'm sorry that I can't report the problem more precisely.
                                  Greetings from Germany
                                  Heinz Grandjean
                                  Heinz Grandjean
                                  http://www.estwgj.com/

                                  Comment


                                  • #18
                                    Since the IsFile works as expected, it would appear that EXEcrypt is doing something perhaps?

                                    A simple test you can try with and without the encryption program.

                                    Code:
                                    #COMPILE EXE
                                    #DIM ALL
                                    FUNCTION PBMAIN () AS LONG
                                        IF ISFILE ("myFile_V5.dat") THEN
                                            ? "Found the file"
                                        ELSE
                                            ? "Failed"
                                        END IF
                                    END FUNCTION
                                    Rick Angell

                                    Comment


                                    • #19
                                      Thanks Richard,

                                      Yes I've done this.
                                      I checked the return value of IsFile() and I got in some cases a zero
                                      in the protected application..
                                      Sorry that I'm not able to find a system of that.

                                      Maybe ExeCrypt has done something to IsFile(), but it hasn't done it
                                      before...

                                      The main reason why I have posted:
                                      It wasn't a problem before.
                                      Again; I didn't change the code or the ExeCrypt settings.

                                      In great respect to PB, but I think that IsFile() is loosing focus despite of correct file-addressing.

                                      Heinz Grandjean
                                      Heinz Grandjean
                                      http://www.estwgj.com/

                                      Comment


                                      • #20
                                        Originally posted by Bernhard Fomm View Post
                                        Now I need ISFILEORDIR. Or did I miss something?
                                        If IsFile("C:\PathName\NUL") Then {Folder Exists}
                                        Scott Slater
                                        Summit Computer Networks, Inc.
                                        www.summitcn.com

                                        Comment

                                        Working...
                                        X