Results 1 to 34 of 34

Thread: I can't get move() to work! [RESOLVED]

  1. #1

    Thread Starter
    KrisSiegel.com Kasracer's Avatar
    Join Date
    Jul 2003
    Location
    USA, Maryland
    Posts
    4,985

    I can't get move() to work! [RESOLVED]

    Code:
    Dim mov As Directory
    
                Try
                    mov.Move(app & OldFileName, OldPath & OldFileName)
                    MessageBox.Show("Sucess!")
    I am trying to move a file that will be in the same directory as my program to a system directory but it just won't work. I'm not sure *** is wrong!

    app = application.StartupPath
    OldFileName = "\text.txt"
    OldPath = "C:\WINDOWS"

    I used the rename() function to rename something and I am going to replace it with the file that is in the folder with my program. File names in the example are different from what I'm actually doing but it doesn't matter.
    Last edited by Kasracer; Jul 8th, 2003 at 11:27 AM.

  2. #2
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    Are you getting an error? Does nothing happen? What? How do you know it wont work?

    Try:
    VB Code:
    1. Dim sysPath As String = Environment.GetEnvironmentVariable("windir")
    2.         Dim filename As String = "text.txt"
    3.         IO.Directory.Move(IO.Path.Combine(Application.StartupPath, filename), IO.Path.Combine(sysPath, filename))

    PS: Doesn't seem to work if one is a network share or mapped network drive.

  3. #3

    Thread Starter
    KrisSiegel.com Kasracer's Avatar
    Join Date
    Jul 2003
    Location
    USA, Maryland
    Posts
    4,985
    I just tried that and it didn't work. Ugh I'm gonna turn off my custom error handling message boxes and see what it actaully says the error is.

    EDIT: It says something about the root of the start and end must be identical, and it cannot move accross volumes... but they ARE identical! Ugh now I'm lost.
    Last edited by Kasracer; Jul 7th, 2003 at 02:42 PM.

  4. #4

  5. #5

    Thread Starter
    KrisSiegel.com Kasracer's Avatar
    Join Date
    Jul 2003
    Location
    USA, Maryland
    Posts
    4,985
    Yes, I know..... I posted that question, you answered it and I tried to impliment it. Rename() works perfectly, however, move() refuses to co-operate.

    Now I got another problem! VB cannot remember my Tab order! I got a form with a bunch fo tabs, and when I re-arrang them it shows them as re-arranged but then I compile it shows it in a completely screwed up order and the collection of tabs changes as well but the form doesn't until I close and re-open it. UGH!!

  6. #6
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    If rename works then just use it and don't change the name, instead of move.

  7. #7
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    When using Move , you have to specify both the path and the file name for both Original and destination .

  8. #8

    Thread Starter
    KrisSiegel.com Kasracer's Avatar
    Join Date
    Jul 2003
    Location
    USA, Maryland
    Posts
    4,985
    Originally posted by Pirate
    When using Move , you have to specify both the path and the file name for both Original and destination .
    I need to get the file out of the same directory as the program, so if the user decides to put my program's directory in another place, they wouldn't be able to use this AT ALL.

  9. #9
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    lol ... How then you would move a file without specifying the path ?? What I mean is you have to combine the file name(and ext) with the path whether it's original or target paths . You can do it in different ways : make a file explorer or textbox to let the user type the path or load content of a directory in treeview or or or . I dunno why you are getting troubles with that , it's working well here .

  10. #10

    Thread Starter
    KrisSiegel.com Kasracer's Avatar
    Join Date
    Jul 2003
    Location
    USA, Maryland
    Posts
    4,985
    Originally posted by Pirate
    lol ... How then you would move a file without specifying the path ?? What I mean is you have to combine the file name(and ext) with the path whether it's original or target paths . You can do it in different ways : make a file explorer or textbox to let the user type the path or load content of a directory in treeview or or or . I dunno why you are getting troubles with that , it's working well here .
    I have 1 file in the directory of my program, I need it to be moved to a system directory. The user shouldn't have to say where the file is, this is something that should be automatic without ANY user involvement.

    Right now I'm trying to move a file with the application.startuppath and the file name to the system folder with the same file name.

  11. #11
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    Actually we are all lame the problem is you are using the DIRECTORY.Move method instead of the FILE.Move method.
    VB Code:
    1. Dim sysPath As String = Environment.GetEnvironmentVariable("windir")
    2.         Dim filename As String = "text.txt"
    3.         IO.File.Move(IO.Path.Combine(Application.StartupPath, filename), IO.Path.Combine(sysPath, filename))

    Although rename takes the same basic parameters as move so the only difference would have been to use Rename instead of Move.

  12. #12

    Thread Starter
    KrisSiegel.com Kasracer's Avatar
    Join Date
    Jul 2003
    Location
    USA, Maryland
    Posts
    4,985
    Originally posted by Edneeis
    Actually we are all lame the problem is you are using the DIRECTORY.Move method instead of the FILE.Move method.
    VB Code:
    1. Dim sysPath As String = Environment.GetEnvironmentVariable("windir")
    2.         Dim filename As String = "text.txt"
    3.         IO.File.Move(IO.Path.Combine(Application.StartupPath, filename), IO.Path.Combine(sysPath, filename))

    Although rename takes the same basic parameters as move so the only difference would have been to use Rename instead of Move.
    No I am using that code. WIth the Mov.Move() in that file, I got errors. Even when I imported some stuff it just didn't work right. I changed it to the code you posted, still won't work!

  13. #13
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    Maybe the trouble is not the code but something else. When you say it doesn't work what does that mean? Are you getting an error if so then what error?

    That code worked for me. Is this an ASP.NET project if so does the ASP.NET user or whatever user you are using to run it with have IO Permissions to move files?

  14. #14
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    You can use GetFiles() function to get the file you want without user interaction . Then move or rename it .

    edit : the problem is not the code I and Edneeis posted , it's you . Sorry .

  15. #15

    Thread Starter
    KrisSiegel.com Kasracer's Avatar
    Join Date
    Jul 2003
    Location
    USA, Maryland
    Posts
    4,985
    Originally posted by Pirate
    You can use GetFiles() function to get the file you want without user interaction . Then move or rename it .

    edit : the problem is not the code I and Edneeis posted , it's you . Sorry .
    I copied and pasted that code, then modified the receiving directory, it just refuses to work!

    bah!

  16. #16
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    Can you upload your project ??

  17. #17

    Thread Starter
    KrisSiegel.com Kasracer's Avatar
    Join Date
    Jul 2003
    Location
    USA, Maryland
    Posts
    4,985
    Code:
    IO.Directory.Move(IO.Path.Combine(Application.StartupPath, FileName), IO.Path.Combine(endPath, FileName))
                MessageBox.Show("Patch Successful!")
    I can't upload it right now cause my program is no where near finished and the code isn't cleaned up.

    Code:
    Dim sysPath As String = Environment.GetEnvironmentVariable("windir")
            Dim endPath As String = sysPath + "\System32\"
    The variables

  18. #18
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    What about the variable "FileName" ?? Can you take a screen shot of a msgbox shown the paths for orginial and target before you do your operation ?? Maybe a slash or missing symbol ...Weird it's working on my machine.

  19. #19

    Thread Starter
    KrisSiegel.com Kasracer's Avatar
    Join Date
    Jul 2003
    Location
    USA, Maryland
    Posts
    4,985
    Code:
    Dim FileName As String = "weeee.txt"
    It never moves the file at all. Just gives me an error saying the system root must be the same for the destination and the origin

  20. #20
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    And where is this file ?? Can you paste the path here ??

  21. #21

    Thread Starter
    KrisSiegel.com Kasracer's Avatar
    Join Date
    Jul 2003
    Location
    USA, Maryland
    Posts
    4,985
    Originally posted by Pirate
    And where is this file ?? Can you paste the path here ??
    The file is wherever the exe is. Same folder.

    The output is C:\WINDOWS\system32

  22. #22
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    Although , it shouldn't be different , but what's your OS and File System ?

  23. #23

    Thread Starter
    KrisSiegel.com Kasracer's Avatar
    Join Date
    Jul 2003
    Location
    USA, Maryland
    Posts
    4,985
    Originally posted by Pirate
    Although , it shouldn't be different , but what's your OS and File System ?
    Windows XP Pro
    NTFS

  24. #24
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    You are still using Directory instead of File. You must have cut and pasted the first set of code not the second. Using File instead of Directory should solve the error about the same root. Also if you want the System32 folder then you can use a different environmental variable.

    VB Code:
    1. Dim sysPath As String = Environment.SystemDirectory
    2.         Dim filename As String = "text.txt"
    3.         IO.[b][color=red]File[/color][/b].Move(IO.Path.Combine(Application.StartupPath, filename), IO.Path.Combine(sysPath, filename))

  25. #25
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    Edneeis both ways run can do the same thing . He's doing something wrong maybe in the file or something . I dunno ...
    anyways , I tried this , it's workin also . Use this (copy and paste) and create a textfile under bin\ folder named "weeee.txt" , you should find it in Windows\System32 folder . That's all what I can do about it . Can't see anything wrong .
    VB Code:
    1. Public Function MoveMe() As Boolean
    2.         Dim OldPath As String = Application.StartupPath
    3.         Dim OldFileName As String = "\weeee.txt"
    4.         Dim DesPath As String = "C:\Windows\System32"
    5.  
    6.  
    7.         Dim mov As Directory
    8.  
    9.         Try
    10.             mov.Move(OldPath & OldFileName, DesPath & OldFileName)
    11.             MessageBox.Show("File was moved to ..." & DesPath)
    12.             Return True
    13.  
    14.         Catch ex As Exception
    15.             MsgBox(ex.Message)
    16.             Return False
    17.         End Try
    18.     End Function

  26. #26
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    I get the error like he mentioned when I run that or use the Directory.Move method.

    Although the project files and the destination aren't on the same root or drive on my machine. One is on E:\ and the Other is on C:\
    Last edited by Edneeis; Jul 7th, 2003 at 06:20 PM.

  27. #27

    Thread Starter
    KrisSiegel.com Kasracer's Avatar
    Join Date
    Jul 2003
    Location
    USA, Maryland
    Posts
    4,985
    Originally posted by Edneeis
    VB Code:
    1. Dim sysPath As String = Environment.SystemDirectory
    2.         Dim filename As String = "text.txt"
    3.         IO.[b][color=red]File[/color]<b>You are still using Directory instead of File.  You must have cut and pasted the first set of code not the second.  Using File instead of Directory should solve the error about the same root.  Also if you want the System32 folder then you can use a different environmental variable.
    4.  
    5. </b>.Move(IO.Path.Combine(Application.StartupPath, filename), IO.Path.Combine(sysPath, filename))
    [/B]
    Worked Perfectly! Thanks! I didn't realize I was using IO.Directory still. IO.File works fine.

    EDIT: Now my tabs are working fine... hmm o well
    Last edited by Kasracer; Jul 7th, 2003 at 06:25 PM.

  28. #28
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    . Kidding . I tested it three times . Trust me , it's working . Can't help anymore . Out of thughts .

  29. #29
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    I think it only works if the original root and destination root are on the same drive. I believe you, but I have my projects on a seperate drive. I tried it on another computer and the samething happened but there the projects where on a networked drive so its the same deal.

    I didn't test it where both roots are the same drive but if you did and it worked then I'm sure it would.

  30. #30
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    It seems true Edneeis . I've just tried moving the file to another partition but gave me that error too . Phew , that sux . . kasracer didn't tell us he's trying to move a file to another partition .

  31. #31
    Fanatic Member
    Join Date
    Jun 2001
    Posts
    521
    Please change the topic of this thread to include [RESOLVED] -- I was about to say use File.Move when it had already been suggested. It'd also be very nice to add a post at the end summing up the solution to make it easy for people searching the forums to learn from your mistake
    I have two simple requests: 1) Use useful and specific topics. 2) Modify your topic to include [Resolved] when you problem has been resolved. Both of these make the bulletin boards more useful and efficient. Thanks.

  32. #32

    Thread Starter
    KrisSiegel.com Kasracer's Avatar
    Join Date
    Jul 2003
    Location
    USA, Maryland
    Posts
    4,985
    Originally posted by VictorB212
    Please change the topic of this thread to include [RESOLVED] -- I was about to say use File.Move when it had already been suggested. It'd also be very nice to add a post at the end summing up the solution to make it easy for people searching the forums to learn from your mistake
    Sorry, I'm used to forums which don't allow users to alter there title after posting.

  33. #33
    Fanatic Member
    Join Date
    Jun 2001
    Posts
    521
    Get used to the higher quality forums here then
    I have two simple requests: 1) Use useful and specific topics. 2) Modify your topic to include [Resolved] when you problem has been resolved. Both of these make the bulletin boards more useful and efficient. Thanks.

  34. #34
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    Originally posted by VictorB212
    Get used to the higher quality forums here then
    Used to be that but after those spams all over the boards , it sukx

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width