File copy VB Exp 2005

D

Darhl Thomason

I thought I was creating a simple little app, but it's kicking my butt right
now. I've searched the help and can't find enough to get me where I need to
be.

I'm creating a CD to distribute to my field personnel. The purpose of the
app is to copy some files from the CD to an obscure destination directory on
the machine. The destination directory can change on the target machine and
is identified as IcmPath. (IcmPath is populated elsewhere in the code).

The first problem is with the source. I have to explicitly name the files I
want to copy, but I would prefer to not so I don't have to recompile the app
everytime the source files change and a new CD is built.

So, as in my example below, when I specify the files to copy and run this,
it tells me that my destination directory already exists. But it will
always exist, it is put in place by the original software installation and
contains sub directories.

I guess I'm kind of confused about how to do this. Any help would be
appreciated!

Thanks,

Darhl

Private Sub cmdYes_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles cmdYes.Click

Source = "\files\pos.ico"

Dest = IcmPath & "\ICM\Package"

My.Computer.FileSystem.CopyFile(Source, Dest)

MsgBox("Files copied into " & IcmPath & "\ICM\Package")

End Sub
 
J

Jim Wooley

So, as in my example below, when I specify the files to copy and run
this, it tells me that my destination directory already exists. But
it will always exist, it is put in place by the original software
installation and contains sub directories.
Private Sub cmdYes_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles cmdYes.Click

Source = "\files\pos.ico"

Dest = IcmPath & "\ICM\Package"

My.Computer.FileSystem.CopyFile(Source, Dest)

MsgBox("Files copied into " & IcmPath & "\ICM\Package")

End Sub

It appears that you are trying to copy the file to the directory, not into
it. Try to tack on the \pos.ico to the end of your Dest string as follows:
Dest = IcmPath & "\ICM\Package\pos.ico"

Additionally, you may want to take the overload on the CopyFile method that
forces an overwrite:
My.Computer.FileSystem.CopyFile(Source, Dest, True)

Jim Wooley
http://devauthority.com/blogs/jwooley/default.aspx
 
D

Darhl Thomason

Hi Jim,

That did work, but I really don't want to have to specify the files. I'm
just using pos.ico as a test bed, but in reality, there may be up to 10
files in the \files directory on the CD that need to be copied into the
IcmPath\ICM\Package folder. I want the app to find the names on it's own,
not specify them. Is this possible? I've tried putting *.* in place of
pos.ico and it squawks that there are illegal characters in the path.

Thanks!

Darhl
 
J

Jim Wooley

Hi Jim,
That did work, but I really don't want to have to specify the files.
I'm just using pos.ico as a test bed, but in reality, there may be up
to 10 files in the \files directory on the CD that need to be copied
into the IcmPath\ICM\Package folder. I want the app to find the names
on it's own, not specify them. Is this possible? I've tried putting
*.* in place of pos.ico and it squawks that there are illegal
characters in the path.

I don't believe you can use a wild card search, but you could try modifying
the following to suit your purposes:

For Each f As String In System.IO.Directory.GetFiles("c:\windows")
If System.IO.Path.GetExtension(f) = ".ico" Then
System.IO.File.Move(f, DestPath & System.IO.Path.GetFileName(f))
End If
Next

Jim Wooley
http://devauthority.com/blogs/jwooley/default.aspx
 
D

Darhl Thomason

That looks like it may be what I want...can the "System.IO.File.Move" be
"System.IO.File.Copy"? Since it will ultimately be coming off a CD, the
files won't be moveable...

Thanks again!

Darhl
 
J

Jim Wooley

That looks like it may be what I want...can the "System.IO.File.Move"
be "System.IO.File.Copy"? Since it will ultimately be coming off a
CD, the files won't be moveable...

Should be able to. Just watch out for the read only flag. Files on the CD
are automatically tagged as read only which sometimes causes problems down
the road when copying.

Jim Wooley
http://devauthority.com/blogs/jwooley/default.asp
 
D

Darhl Thomason

Thanks for the suggestions, it works great now. I'll build it and burn it
to CD with the accessory files and see what happens.

Thanks again!

Darhl
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top