Click here to Skip to main content
15,921,793 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Is there any simple way to copy a single file out of one directory to a new one?
I tried this:
VB
Dim path As String = Application.StartupPath + "\Work.xml"
        Dim path2 As String = Application.StartupPath & "\SavedFiles"
        File.Copy(path, path2)

But then I receive an error saying "The target file "C:\Users\User\Desktop\MyProgram\MyProgram\bin\Debug\SavedFiles" is a directory, not a file."
This way doesn't work either:
VB
File.Copy(Application.StartupPath + "\Work.xml", Application.StartupPath + "\SavedFiles")

Any help on how to copy a single file from one directory to a new one would be greatly appreciated.
Posted

1 solution

You have to specify full name as destination
VB
Dim path As String = Application.StartupPath & "\Work.xml"
Dim path2 As String = Application.StartupPath & "\SavedFiles\Work.xml"
File.Copy(path, path2)
 
Share this answer
 
v2
Comments
NY Andrew 18-Aug-11 0:06am    
Oh wow, I tried using the ampersand sign but I used it in both instead of just one. Thanks for the simple fix Prerak! :)
Prerak Patel 18-Aug-11 0:12am    
You are welcome.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900