Copying File

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • lee123
    Contributor
    • Feb 2007
    • 556

    #16
    you hit the nail on the head, i want to be able to type in a folder "Source" in a text box then type in a folder "destinatio n" in second textbox then click on a button to make it all work that way you can control it the way you want to instead of it being hardwired in the code. i think i explained that right. did I?

    lee123

    Comment

    • jg007
      Contributor
      • Mar 2008
      • 283

      #17
      I'm not sure I see what the question is , if you want a textbox just use textbox1.text where I have placed the file name although I would probably be more inclined to use the built in directory / file selection boxes to save misstypes.

      example for selecting folders -


      Code:
              Dim openfolderfialog1 = New FolderBrowserDialog()
              openfolderfialog1ShowDialog()
              foldertocopy = openfolderfialog1.SelectedPath
      you can use ' System.Windows. Forms.OpenFileD ialog ' for selecting a file

      Comment

      • lee123
        Contributor
        • Feb 2007
        • 556

        #18
        I'm Sorry But I tried to put the code the way you have it and it doesn't work. my question was if you were to make a form. you would put two textboxes on it one named "txtSourceofFol der" this would be for entering what folder you want to copy. the other textbox named "txtDestination OfFolder" this would be where you want the folder to be copied to. now to make this all go place a button on the form named "Go" or "Begin" or something like that. the basis of this form would be, you could be incontrol of what folder you wanted to copy and where you would want that folder to be copied to. Because right now i have a form that copies the folder and places it in a folder i had to program in the code but that's no fun. I would rather have it the way i have discribed it. so if you could help me do this well that would be great!

        lee123

        Comment

        • jg007
          Contributor
          • Mar 2008
          • 283

          #19
          If I underastand that would be pretty simple as above just replace folder names with the textbox values

          I'm not too sure why the code I posted above will not work but it may be becase I am using vb.net , think I need to find a copy of vb 6 to save me confusing people !


          Code:
          Private Sub CmdSomeButton_Click()
          
          Dim fso As New Scripting.FileSystemObject
          Dim fld As Folder
          Set fld = fso.GetFolder(txtSourceofFolder.text)
          fld.Copy (txtDestinationOfFolder.text)
          MsgBox "Transfer Completed!"
          End Sub

          Comment

          • jg007
            Contributor
            • Mar 2008
            • 283

            #20
            just noticed that I missed out a ' . ' somehow :)

            Code:
            Dim openfolderfialog1 = New FolderBrowserDialog()
            openfolderfialog1.ShowDialog()
            foldertocopy = openfolderfialog1.SelectedPath

            Comment

            • vdraceil
              New Member
              • Jul 2007
              • 236

              #21
              Originally posted by lee123
              I'm Sorry But I tried to put the code the way you have it and it doesn't work. my question was if you were to make a form. you would put two textboxes on it one named "txtSourceofFol der" this would be for entering what folder you want to copy. the other textbox named "txtDestination OfFolder" this would be where you want the folder to be copied to. now to make this all go place a button on the form named "Go" or "Begin" or something like that. the basis of this form would be, you could be incontrol of what folder you wanted to copy and where you would want that folder to be copied to. Because right now i have a form that copies the folder and places it in a folder i had to program in the code but that's no fun. I would rather have it the way i have discribed it. so if you could help me do this well that would be great!

              lee123
              Try this lee..(single line code)

              fso.copyfolder text1.text,text 2
              .text

              Comment

              • lee123
                Contributor
                • Feb 2007
                • 556

                #22
                Well vb.net or not JG007 The code you have posted works great thanks for it, Sometime the code that vb.net uses works why I don't know, But your right I should of let you both know what version i was using and it was Visual Basic 6.0 and for that I'm very sorry but thanks the both of you for you help.

                this is the one I used:

                Code:
                Private Sub CmdSomeButton_Click()
                 
                Dim fso As New Scripting.FileSystemObject
                Dim fld As Folder
                Set fld = fso.GetFolder(txtSourceofFolder.text)
                fld.Copy (txtDestinationOfFolder.text)
                MsgBox "Transfer Completed!"
                End Sub
                lee123

                Comment

                • programpro
                  New Member
                  • Sep 2008
                  • 1

                  #23
                  if you're using Visual Basic .NET, why not just use the My object? It's really easy to use.
                  Code:
                  My.Computer.FileSystem.CopyFile(sourceFileName, destinationFileName, overwriteBoolean)
                  I really use this a lot and it is very 'basic'.
                  Hope this helps,
                  Sam


                  _______________ _______________ _______________ __
                  Visit my site:
                  www.inno-tron.com

                  Comment

                  • jg007
                    Contributor
                    • Mar 2008
                    • 283

                    #24
                    that is the fun of programming :), 50 different ways to achieve a goal . thanks for that I will 'try' to remember that one !

                    most of my programming is just pieced together from what I pick up when I need to do something so is not always the quickest or more efficient way and it is always great to see easier or better ways of doing something

                    Comment

                    Working...