Announcement

Collapse
No announcement yet.

OPEN with non-existant File Path

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

  • OPEN with non-existant File Path

    I'm trying to use the OPEN keyword in PBDLL 6.0 with a File Name that
    included a path that does not exist. I keep getting an error 76 on
    the OPEN statment. So I added code to us MKDIR to create the path if
    if didn't exist but it also returns an error 76. I'm using Windows
    2000 Professional and the path does use long file names. Any ideas?

    ------------------
    Thanks,

    Doug Gamble
    mailto:[email protected][email protected]</A>
    Thanks,

    Doug Gamble
    [email protected]

  • #2
    MKDIR can only create a single directory at a time. If the path involves
    nested directories, you need to account for this by creating the top directory
    first, then the next, and so forth. There's probably code to do this here
    already. Try a Forum search.

    ------------------
    Tom Hanlin
    PowerBASIC Staff

    Comment


    • #3
      Thanks Tom...Thank explains the problem. I'll check the forum
      again but didn't see anything like that on my first look before
      posting the message. If I get something working I'll post it.

      ------------------
      Thanks,

      Doug Gamble
      mailto:[email protected]h.com[email protected]</A>
      Thanks,

      Doug Gamble
      [email protected]

      Comment


      • #4
        Doug,
        The following code is what I use to build nested directories.
        The subroutine ignores errors. It is the programmers responsibility to verify creation of the directory.

        This will build complete directories using standard paths and UNC paths.

        Code:
        SUB BuildDir (BYVAL Path$) 
           drive$=""
           
           'Strip off trailing backslash
           IF RIGHT$(Path$,1)="\" THEN
              Path$=MID$(Path$,1,LEN(Path$)-1)
           END IF
        
           'Check for UNC Path and make drive$ = to machine name
           IF MID$(Path$,1,2)="\\" THEN
              temp_pos&=instr(3,Path$,"\")
              drive$=mid$(Path$,1,temp_pos&-1)
              Path$=MID$(Path$,len(drive$)+2)
              root&=1
           ELSE
              IF MID$(Path$,1,1)="\" THEN
                 Path$=MID$(Path$,2)
                 root&=1
              END IF
           END IF
        
           IF MID$(Path$,2,1)=":" THEN
              drive$=MID$(Path$,1,2)
              Path$=MID$(Path$,3)
              IF MID$(Path$,1,1)="\" THEN
                 Path$=MID$(Path$,2)
                 root&=1
              END IF
           END IF
        
           'Loop through path building directories as needed....
           FOR i&=1 TO LEN(Path$)
              c$=MID$(Path$,i&,1)
              IF c$="\" THEN
                 ON ERROR RESUME NEXT
                    IF root& THEN
                       MKDIR drive$+"\"+a$
                    ELSE
                       MKDIR a$
                    END IF
                 ON ERROR GOTO 0
              END IF
              a$=a$+c$
           NEXT i&
           ON ERROR RESUME NEXT
              IF root& THEN
                 MKDIR drive$+"\"+a$
              ELSE
                 MKDIR a$
              END IF
           ON ERROR GOTO 0
        END SUB
        ------------------
        James Moneypenny
        James Moneypenny
        mailto:[email protected][email protected]</A>

        Comment


        • #5
          As I understad it, PB/Win does not support call interrupts as
          PB/DOS does. However, the following snippit should be
          translatable into ASM statements/functions and should work.
          When called, if the sub-directory exists, AX = 0. If it doesn't
          exist, AX = 3. This allows for testing the complete
          sub-directory (without file names) existance without crashing
          the program.

          SubDir$ = SubDir$ + chr$(0)
          reg 1, &h3b00
          reg 4, strptr(subdir$)
          reg 8, strseg(subdir$)
          call interrupt &h21
          SubExists = reg(1)

          Lance, if I'm completely out in left field, please feel free
          to delete this post.


          ------------------
          There are no atheists in a fox hole or the morning of a math test.
          If my flag offends you, I'll help you pack.

          Comment


          • #6
            Mel, you cannot call Real-mode interrupts from a Protected mode application (ie, a 32-bit Windows EXE or DLL).

            In other words: calling a DOS interrupt from a Windows program earns you one GPF point for trying!



            ------------------
            Lance
            PowerBASIC Support
            mailto:[email protected][email protected]</A>
            Lance
            mailto:[email protected]

            Comment


            • #7
              Little known api call will create directory structure
              IMAGEHLP.DLL is part of IE 4.0 or Win98 and later, so most PC's should have it

              Code:
              Declare Function MakeSureDir LIB "IMAGEHLP.DLL" Alias "MakeSureDirectoryPathExists" (lpDirName As Asciiz) As Long
              
              Sub CheckDir(TestDir As String)
                  Dim RetVal As Long
                  Dim DirPath As Asciiz * MAX_PATH
                  ' The ending backslash is necessary
                  DirPath = TestDir & Chr$(0)
                  RetVal = MakeSureDir(DirPath)
              End Sub
              Hope this helps
              Joe Murphy

              ------------------

              Comment


              • #8
                Hmmm... you can trim that SUB down a tad by removing the unnecessary string conversion, and passing the address of the dynamic string data directly to the API. Internally, all dynamic strings have a trailing CHR$(0), so adding one just wastes a wee bit of time. Also, since you are not returning the error/success code, you can CALL the API instead. Finally, just ensure you don't pass an empty string to the SUB.
                Code:
                Sub CheckDir(TestDir As String)
                  CALL MakeSureDir(BYVAL STRPTR(TestDir))
                End Sub
                ------------------
                Lance
                PowerBASIC Support
                mailto:[email protected][email protected]</A>
                Lance
                mailto:[email protected]

                Comment

                Working...
                X