Delete file or folder

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Killer42
    Recognized Expert Expert
    • Oct 2006
    • 8429

    #16
    Personally, I think that the FileSystemObjec t is overkill for such a simple operation. To empty out the contents of a file, you can can use two simple statements.
    Code:
    Open "YourFile.Txt" For Output Access Write Lock Write As #1
    Close #1

    Comment

    • kuzure
      New Member
      • Dec 2006
      • 48

      #17
      Originally posted by Killer42
      Personally, I think that the FileSystemObjec t is overkill for such a simple operation. To empty out the contents of a file, you can can use two simple statements.
      Code:
      Open "YourFile.Txt" For Output Access Write Lock Write As #1
      Close #1

      Thanks for the reply, it works!!! This code is easier than delete and replace another file. haha^^

      By the way, the code that used FileSystemObjec t still not working. I hope I can work it out later, I need to learn more than one way.

      Thanks again everyone.

      Best Regards.

      Comment

      • sukeshchand
        New Member
        • Jan 2007
        • 88

        #18
        The file system object is a class with vb. lots of file handling methods are avilable in it.

        Try the following code...
        Code:
        Dim FObj As New FileSystemObject
        FObj.CreateTextFile "C:\test345.txt", True

        Comment

        • Killer42
          Recognized Expert Expert
          • Oct 2006
          • 8429

          #19
          Originally posted by kuzure
          Thanks for the reply, it works!!! This code is easier than delete and replace another file. haha^^
          Glad to hear it worked out. :)

          Originally posted by kuzure
          By the way, the code that used FileSystemObjec t still not working. I hope I can work it out later, I need to learn more than one way.
          Yes, you should. The FileSystemObjec t provides lots of options - this was a very simple case. And it's good to know more than one way to do things.

          Comment

          • Titan45
            New Member
            • Oct 2008
            • 1

            #20
            Hello everyone---

            kuzure, if it's alright, I'm going to steal your spotlight for a moment. If I could trouble someone really quickly, that would be great. =P

            I am trying to delete a file as well (well, really, it's a program I am building for my friend): he happens to play World of Warcraft and there is a Cache folder within WoW's (World of Warcraft) respective directory -- usually based in Program Files. Everytime WoW is run, it adds on to the Cache folder with every new "encounter" with an item, creature, etc... In order to play different private servers, my friend, as does everyone else, is encouraged to delete their Cache folder in order for a server's settings to work out properly. Every time you delete it, then run WoW, it re-creates itself to store the new settings.

            I am working on having a button be set to delete the Cache folder and another to run the game. If I could possibly be informed of a code using: Const DelCache As String = "C:\Program Files\World of Warcraft\Cache" as the constant used in the click event for the button deleting the Cache folder.

            What I am hoping to do is have it check if the folder exists, then to delete it if so. So obviously I need an If-Then-Else statement containing the folder existence-check and the deletion.

            As for the code pertaining to running WoW -- a simple code would do just fine, although there really isn't a complex one at that.

            Comment

            • jg007
              Contributor
              • Mar 2008
              • 283

              #21
              some of the questions here are very basic and although it is great to help please do start with a few basic tutorials before posting , there are many great links and tutorials available via google or your prefered search engine

              there are also many filesystem object tutorials available


              for the code 'Dim FileSystemObjec t As New FileSystemObjec t '

              you cannot use the filesystem object directly so you need to create a new instance of it,

              click here for some more info on FSO

              (apologies if I am miss understanding the question )

              below is an example of a very simple sub called ' example ' when you click button 1 it calls the sub and passes it the value of textbox1 which the sub then shows in a message box

              Code:
              
              Public Class Form1
              
                  Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
                      example(TextBox1.Text)
                  End Sub
                  Private Sub example(ByVal Message_To_Show As String)
              
                      msgbox(Message_To_Show)
              
                  End Sub
              End Class

              Comment

              Working...