filesystemobject.movefolder?

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

    filesystemobject.movefolder?

    why is this so hard to do. i have alot of books that have exaples of how to do these things but when i try the exaples they never work i have a previous post on "copying files" some of the other guys help on this one and i tried to do the same thing with the "movefile" but it never worked as you can see the "filesystemobje ct" is hard to accomplish for me because this "Movefolder " event falls in this category the code i have i have used for the copyfolder event right here:

    Code:
    Dim fso As New Scripting.FileSystemObject
    Dim fld As Folder
    Set fld = fso.GetFolder(txtSourceOfFolder)
    fld.Copy (txtDestinationOfFile)
    this is to copy the folder. How can i use this to move the folder to another folder of my choosing. because i have tried this:

    Code:
    Dim fso As New FileSystemObject
    Dim fldr As Folder
    Set fso = fso.GetFolder(TxtSource.Text)
    fldr.Move (TxtDestination.Text)
    MsgBox "Moved"
    so can someone tell me or explain to me why it doesn't work. is there something There not explaining in these books? or is this "filesystemobje ct" a hard cookie to crack.

    lee123
  • jg007
    Contributor
    • Mar 2008
    • 283

    #2
    not sure if this was just a miss type but you are not assigning the fldr variable before trying to use it

    your code -

    Code:
    Dim fso As New FileSystemObject
    Dim fldr As Folder
    Set fso = fso.GetFolder(TxtSource.Text)
    fldr.Move (TxtDestination.Text)
    MsgBox "Moved"
    works as

    Code:
    Dim fso As New FileSystemObject
    Dim fldr As Folder
    Set fldr= fso.GetFolder(TxtSource.Text) ' <------ note the change here 
    fldr.Move (TxtDestination.Text)    
    MsgBox "Moved"

    Comment

    • jg007
      Contributor
      • Mar 2008
      • 283

      #3
      it also helps if you post any errors you receive as in this case I would have expected to see -

      ' Warning 1 Variable 'fldr' is used before it has been assigned a value. A null reference exception could result at runtime.


      I'm not to sure of the exact terms but fso is just a pointer to the filesystemobjec t and you then use getfolder to assign a specific folder to fldr , once fldr is pointed at a folder you can user the function to move it.

      Comment

      • lee123
        Contributor
        • Feb 2007
        • 556

        #4
        hey there, ok it was a miss type on my part, i got so fustrated doing it so many ways that i forgot to change it back to "fldr" and the error I'm getting is "Permssion Denied" and it keeps pointing to this part of the code:

        Code:
        fldr.Move (TxtDestination.Text)
        is it because there are files in this folder? or I can't express the code this way. How Can I do This?

        lee123

        Comment

        • lee123
          Contributor
          • Feb 2007
          • 556

          #5
          Oh Yea I have tried it this way too but keep getting an error: "Compile Error: Argument not Optional"

          Code:
          Private Sub cmdMove_Click()
          Dim fso As New FileSystemObject
          Dim fldr As Folder
          Set fldr = fso.MoveFolder(TxtSource.Text) <----- I changed it here
          fldr.Move (TxtDestination.Text)
          MsgBox "Moved"
          End Sub
          and it points to this part of the code:

          Code:
          Set fldr = fso.[B]MoveFolder[/B](TxtSource.Text) <-----Where Bolded
          in the book i have this is what it says to do.

          lee123

          Comment

          • ubentook
            New Member
            • Dec 2007
            • 58

            #6
            MoveFolder requires two arguments...
            fso.MoveFolder( Source, Destination)

            Move requires one argument...
            fldr.Move(Desti nation)


            Originally posted by lee123
            Oh Yea I have tried it this way too but keep getting an error: "Compile Error: Argument not Optional"


            and it points to this part of the code:
            Code:
            Set fldr = fso.[B]MoveFolder[/B](TxtSource.Text) <-----Where Bolded
            lee123

            Comment

            • lee123
              Contributor
              • Feb 2007
              • 556

              #7
              So what are you saying.....My way won't Work? or Can't work the way I want it to?

              lee123

              Comment

              • ubentook
                New Member
                • Dec 2007
                • 58

                #8
                The answer is... Yes

                Comment

                • lee123
                  Contributor
                  • Feb 2007
                  • 556

                  #9
                  So How Would you Go about Doing this?

                  lee123

                  Comment

                  • !NoItAll
                    Contributor
                    • May 2006
                    • 297

                    #10
                    I don't believe move or movefolder will work across drives if that's what you are trying to do.

                    Comment

                    • lee123
                      Contributor
                      • Feb 2007
                      • 556

                      #11
                      is there a function that will? for example move one forder (lets say in C:\) to another (lets say in D:\)

                      lee123

                      Comment

                      • ubentook
                        New Member
                        • Dec 2007
                        • 58

                        #12
                        Copy the folder to the other drive then delete the original folder...

                        Sub MoveAndConfuse( )
                        Dim fso As Scripting.FileS ystemObject
                        Dim fldr As Scripting.Folde r
                        Set fso = New Scripting.FileS ystemObject
                        Set fldr = fso.GetFolder(" C:\Documents and Settings\user\M y Documents\Folde rName")
                        fso.CopyFolder fldr.Path, "F:\Scotch Tape\"
                        fldr.Delete
                        Set fldr = Nothing
                        Set fso = Nothing
                        End Sub

                        Comment

                        • lee123
                          Contributor
                          • Feb 2007
                          • 556

                          #13
                          Thank You : UBentToo, for that it works.. this "filesystemobje ct" is hard to figureout but i have learned alot from it thanks again.

                          lee123

                          Comment

                          Working...