• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 332
  • Last Modified:

File.move

Hi there
I am trying to use the move command to move a folder, i have used the code from MSDN and it work pretty well just one problem the file is moved but there is no data inside the moved file. I am sure it is something small but is missing it, here i my code
Try
                If File.Exists(path) = False Then
                    ' This statement ensures that the file is created,
                    ' but the handle is not kept.
                    Dim fs As FileStream = File.Create(path1)
                    fs.Close()
                End If

                ' Ensure that the target does not exist.
                If File.Exists(path2) Then
                    File.Delete(path2)
                End If

                ' Move the file.
                File.Move(path1, path2)

            Catch

            End Try

Open in new window

0
Andre_p
Asked:
Andre_p
  • 2
2 Solutions
 
CodeCruiserCommented:
Why do you have this part?

If File.Exists(path) = False Then
                    ' This statement ensures that the file is created,
                    ' but the handle is not kept.
                    Dim fs As FileStream = File.Create(path1)
                    fs.Close()
                End If


Also, you have "path" in one place and "path1" in another place. Which one is holding the source file name?
0
 
Carlos VillegasFull Stack .NET DeveloperCommented:
Hello, if your project has Option Explicit = Off it will compile, but if you mistyped File.Exists(path) it always is going to return False (because path is Nothing), so your source file (path1) is always overwrited by Dim fs As FileStream = File.Create(path1), so I think that you need is change File.Exists(path) to File.Exists(path1), result file in path2 is empty.
0
 
Carlos VillegasFull Stack .NET DeveloperCommented:
Ignore last sentence:
, result file in path2 is empty.
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now