Writing files in VB6, stumped.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ohshhitscarl
    New Member
    • Feb 2007
    • 7

    Writing files in VB6, stumped.

    I am in the process of creating an application that runs in the background and performs several tasks and works as a server. At a point in my application I have it write some files to a directory of the user's choice.

    Code:
    Dim TextString As String
    TextString$ = txtSave
    Open Path$ For Output As #1
    Print #1, TextString$
    Close #1
    The only problem that I encounter is that I get this error when the user tries to delete that directory later:

    "Cannot delete folder: It is being used by another person or program."

    The only way to remedy the problem is by shutting down the server application but this is not favorable. Is there any other API or method to get my application to release its "lock" on the directory it wrote the file to?

    Thanks in advance!
  • vijaydiwakar
    Contributor
    • Feb 2007
    • 579

    #2
    Originally posted by ohshhitscarl
    I am in the process of creating an application that runs in the background and performs several tasks and works as a server. At a point in my application I have it write some files to a directory of the user's choice.

    Code:
    Dim TextString As String
    TextString$ = txtSave
    Open Path$ For Output As #1
    Print #1, TextString$
    Close #1
    The only problem that I encounter is that I get this error when the user tries to delete that directory later:

    "Cannot delete folder: It is being used by another person or program."

    The only way to remedy the problem is by shutting down the server application but this is not favorable. Is there any other API or method to get my application to release its "lock" on the directory it wrote the file to?

    Thanks in advance!
    this error is genral whenever u tries to delete that folder then that folder may contain any file which is used by other program to further deletion get terminate
    check the attribute of the file first then try to delete it

    Comment

    • ohshhitscarl
      New Member
      • Feb 2007
      • 7

      #3
      Originally posted by vijaydiwakar
      this error is genral whenever u tries to delete that folder then that folder may contain any file which is used by other program to further deletion get terminate
      check the attribute of the file first then try to delete it
      The users tell me that they are able to delete the files just fine but when they try to delete the folder itself, it gives them that error.

      Comment

      • TNT
        New Member
        • Feb 2007
        • 48

        #4
        Originally posted by ohshhitscarl
        I am in the process of creating an application that runs in the background and performs several tasks and works as a server. At a point in my application I have it write some files to a directory of the user's choice.

        Code:
        Dim TextString As String
        TextString$ = txtSave
        Open Path$ For Output As #1
        Print #1, TextString$
        Close #1
        The only problem that I encounter is that I get this error when the user tries to delete that directory later:

        "Cannot delete folder: It is being used by another person or program."

        The only way to remedy the problem is by shutting down the server application but this is not favorable. Is there any other API or method to get my application to release its "lock" on the directory it wrote the file to?

        Thanks in advance!
        I think that VB6 can only delete direcories if they are empty.

        Comment

        • ohshhitscarl
          New Member
          • Feb 2007
          • 7

          #5
          Originally posted by TNT
          I think that VB6 can only delete direcories if they are empty.
          Well VB6 isn't deleting the directory. The user is deleting it through Windows or through an FTP program.

          VB6 is only writing two files, a ".htaccess" and a ".htpasswd" file. The user reports that the two files can be deleted, but if they try to delete the folder that they were in it gives them the above mentioned error.

          Code:
          User> Tells VB6 program to write files to /home/user/public_html/directory
          VB6> Writes .htaccess & .htpasswd to /home/user/public_html/directory
          User:FTP> Successfully deletes .htaccess & .htpasswd in /home/user/public_html/directory
          User:FTP> Tries to delete /home/user/public_html/directory itself, Unsuccessful.
          Me> In Windows, try to delete /home/user/public_html/directory itself, Error comes up.
          If I close/stop my VB6 app, the folder can be deleted by both myself and the user. The files can be deleted successfully any time without closing the VB6 app.

          Comment

          • Killer42
            Recognized Expert Expert
            • Oct 2006
            • 8429

            #6
            Does your program have anything like a DirListBox control pointing to the folder?

            Comment

            • ohshhitscarl
              New Member
              • Feb 2007
              • 7

              #7
              Originally posted by Killer42
              Does your program have anything like a DirListBox control pointing to the folder?
              No it doesn't. I do use the FileSystemObjec t though to parse through subfolders in the directory, should I destroy it after I'm done with it or would it not make a difference?

              Comment

              • Killer42
                Recognized Expert Expert
                • Oct 2006
                • 8429

                #8
                Originally posted by ohshhitscarl
                No it doesn't. I do use the FileSystemObjec t though to parse through subfolders in the directory, should I destroy it after I'm done with it or would it not make a difference?
                It's quite possible that is what's holding the directory. I would try it, and see what happens.

                Comment

                • ohshhitscarl
                  New Member
                  • Feb 2007
                  • 7

                  #9
                  Originally posted by Killer42
                  It's quite possible that is what's holding the directory. I would try it, and see what happens.
                  Tried setting wFSo to Nothing with no luck.
                  I do have a FileListBox but it doesn't point to any of the directories that would need to be deleted.

                  This really has me completely stumped. :(

                  Thanks for everyone's help so far. Still need a solution.

                  Comment

                  • Killer42
                    Recognized Expert Expert
                    • Oct 2006
                    • 8429

                    #10
                    Originally posted by ohshhitscarl
                    Tried setting wFSo to Nothing with no luck.
                    I do have a FileListBox but it doesn't point to any of the directories that would need to be deleted.

                    This really has me completely stumped. :(

                    Thanks for everyone's help so far. Still need a solution.
                    Hm... while looking for a permanent solution, you might try running a new copy of your program each time, as a workaround. In other words, after your program has "done its thing", shell to another copy of it and end. (Try not to get yourself into an infinite loop and lock up the PC or something.:))

                    Definitely not an elegant solution, but may help to get things moving in the short term.

                    Comment

                    • Killer42
                      Recognized Expert Expert
                      • Oct 2006
                      • 8429

                      #11
                      Originally posted by ohshhitscarl
                      Tried setting wFSo to Nothing with no luck.
                      I do have a FileListBox but it doesn't point to any of the directories that would need to be deleted.
                      You might have to work through your program and isolate each part in turn until you identify the source of the problem.

                      Comment

                      • ohshhitscarl
                        New Member
                        • Feb 2007
                        • 7

                        #12
                        Originally posted by Killer42
                        Hm... while looking for a permanent solution, you might try running a new copy of your program each time, as a workaround. In other words, after your program has "done its thing", shell to another copy of it and end. (Try not to get yourself into an infinite loop and lock up the PC or something.:))

                        Definitely not an elegant solution, but may help to get things moving in the short term.
                        Perhaps an option but definitely not a permanent solution.

                        Without giving any top-secret plans out, my company has hired me to create a cPanel type application for our Windows web servers. This web server runs Winsock arrays and does everything on the fly. Shutting down and restarting would not be an option.

                        I'm not too sure if this would work but if I put the Winsock controls on a different form and have one Main server form just feed RequestIDs and open a New Form every time a request is made, would closing that one form destroy the process id that is using the directories?

                        I don't want to go through the trouble of porting this if it won't work. :)
                        Thanks!

                        Comment

                        • Killer42
                          Recognized Expert Expert
                          • Oct 2006
                          • 8429

                          #13
                          Originally posted by ohshhitscarl
                          Perhaps an option but definitely not a permanent solution.
                          Agreed. Merely a possible short-term workaround while debugging. I wouldn't use it unless really necessary.

                          Originally posted by ohshhitscarl
                          I'm not too sure if this would work but if I put the Winsock controls on a different form and have one Main server form just feed RequestIDs and open a New Form every time a request is made, would closing that one form destroy the process id that is using the directories?
                          I wouldn't know, sorry. However, it does sound worth a try.

                          Originally posted by ohshhitscarl
                          I don't want to go through the trouble of porting this if it won't work.
                          Are you not able to reproduce the problem locally? That would be a huge aid in debugging.

                          The ideal, probably, would be to create a simplified application to try and reproduce and identify the problem, so that you can easily try out options to correct it.

                          Comment

                          • ohshhitscarl
                            New Member
                            • Feb 2007
                            • 7

                            #14
                            Originally posted by Killer42
                            Agreed. Merely a possible short-term workaround while debugging. I wouldn't use it unless really necessary.

                            I wouldn't know, sorry. However, it does sound worth a try.

                            Are you not able to reproduce the problem locally? That would be a huge aid in debugging.

                            The ideal, probably, would be to create a simplified application to try and reproduce and identify the problem, so that you can easily try out options to correct it.
                            Did just that and everything works now! I was actually looking at the wrong code, and it did have something to do with the FileSystemObjec t (I wasn't using it where I needed it) and setting some Access variables to nothing fixed it :)

                            Thanks everyone for the support!

                            Comment

                            • Killer42
                              Recognized Expert Expert
                              • Oct 2006
                              • 8429

                              #15
                              Excellent! Glad we could help.

                              Stick to good, solid debugging techniques for solid results. :)

                              Comment

                              Working...