4 Replies - 1225 Views - Last Post: 18 August 2011 - 08:17 AM Rate Topic: ***** 1 Votes

#1 NY Andrew  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 79
  • Joined: 25-May 11

How can I copy a file from one directory in to a new directory?

Posted 17 August 2011 - 08:41 PM

Is there any simple way to copy a single file out of one directory to a new one?
I tried this:
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:
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.

Is This A Good Question/Topic? 0
  • +

Replies To: How can I copy a file from one directory in to a new directory?

#2 NY Andrew  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 79
  • Joined: 25-May 11

Re: How can I copy a file from one directory in to a new directory?

Posted 17 August 2011 - 09:07 PM

Never mind, I have fixed it:

Dim path As String = Application.StartupPath + "\Work.xml"
Dim path2 As String = Application.StartupPath & "\SavedFiles\Work.xml"
File.Copy(path, path2)

Was This Post Helpful? 0
  • +
  • -

#3 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 9056
  • View blog
  • Posts: 33,994
  • Joined: 12-June 08

Re: How can I copy a file from one directory in to a new directory?

Posted 17 August 2011 - 09:09 PM

Two things.. first MSDN on the function you are trying to use cuts down your problems immensely.
http://msdn.microsof...v=VS.90%29.aspx

Two - read the error. It's telling you that the target file name you are giving it is a directory. Directories are not files. You need to provide the destination file name WITH the directory.
Was This Post Helpful? 0
  • +
  • -

#4 _HAWK_  Icon User is offline

  • Master(Of Foo)
  • member icon

Reputation: 1046
  • View blog
  • Posts: 4,072
  • Joined: 02-July 08

Re: How can I copy a file from one directory in to a new directory?

Posted 17 August 2011 - 09:24 PM

FYI, Application.StartupPath does mean the same after publish - I have tested that. The path you should play with is the Application.ExecutablePath. I usually make directories or path references using:
Directory.GetParent(Application.ExecutablePath).FullName
Was This Post Helpful? 1
  • +
  • -

#5 trevster344  Icon User is offline

  • The Peasant
  • member icon

Reputation: 224
  • View blog
  • Posts: 1,505
  • Joined: 16-March 11

Re: How can I copy a file from one directory in to a new directory?

Posted 18 August 2011 - 08:17 AM

It really couldn't get any simpler, just work at it. :)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1