Home All Groups Group Topic Archive Search About

File copy VB Exp 2005

Author
8 May 2006 4:22 PM
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

Author
8 May 2006 5:14 PM
Jim Wooley
Show quote Hide quote
> 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
Author
8 May 2006 5:21 PM
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


Show quoteHide quote
"Jim Wooley" <jimNOSPAMwooley@hotmail.com> wrote in message
news:24f81e8eb7a98c840b8688006ae@msnews.microsoft.com...
>> 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
>
>
Author
8 May 2006 6:08 PM
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
Author
8 May 2006 6:53 PM
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


Show quoteHide quote
"Jim Wooley" <jimNOSPAMwooley@hotmail.com> wrote in message
news:24f81e8eb8268c840c009f62e68@msnews.microsoft.com...
>> 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
>
>
Author
8 May 2006 7:36 PM
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.aspx
Author
8 May 2006 7:57 PM
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


Show quoteHide quote
"Jim Wooley" <jimNOSPAMwooley@hotmail.com> wrote in message
news:24f81e8eb87e8c840cc58adc8b3@msnews.microsoft.com...
>> 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.aspx
>
>