Furqan Sehgal
Furqan Sehgal

Reputation: 4997

Making folder and copying file

I want my application to look for a file in drive C's specific folder (say C:\myFolder\abc.mdb), if found just give a message if not, make the folder in drive C:\ and then copy the file.

How to do this? Thanks Furqan

Upvotes: 2

Views: 5599

Answers (2)

Abdul
Abdul

Reputation: 11

I know this post is kind of old. I just wanted to update. The quickest shortcut that will also create the Destination directory structure and in one line. Use Computer.FileSystem.CopyFile instead of System.IO.

My.Computer.FileSystem.CopyFile(sSourcefile, sDestinationfile)

Upvotes: 1

Matt
Matt

Reputation: 14551

You could use the File, Directory, and Path objects in the System.IO as shown below:

Imports System.IO

...

Dim path As String = "C:\myFolder\abc.mdb"

If File.Exists(path) Then
     'TODO write code to create message'
Else
     Dim folder As String = Path.GetDirectoryName(path)
     If Not Directory.Exists(folder) then
         Directory.CreateDirectory(folder)
     End If
     'TODO code to copy file from current location to the newly created directory path'
     'i.e. File.Copy(FileToCopy, NewCopy)'
End If

Upvotes: 2

Related Questions