By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,918 Members | 1,852 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,918 IT Pros & Developers. It's quick & easy.

Simple program to copy files? how to?

P: n/a
I want to create a simple program with Two buttons on the form.

BUTTON 1 - BACKUP PREFS
this will do the following:
Copy C:\Documents and Settings\%USERNAME%\Application Data\FileZilla
\sitemanager.xml
to this location: \\drake\pvt\%USERNAME%\FileZilla-Prefs\

BUTTON 2 - RESTORE PREFS
this will do the opposite:
copy sitemanager.xml file from: \\drake\pvt\%USERNAME%\FileZilla-Prefs
\ and put it here:
Copy C:\Documents and Settings\%USERNAME%\Application Data\FileZilla\

And I would like to to not prompt if files exists, just overwrite...

thanks
Sep 16 '08 #1
Share this Question
Share on Google+
10 Replies


P: n/a
On Sep 16, 9:15*pm, Jason <paul...@excite.comwrote:
I want to create a simple program with Two buttons on the form.

BUTTON 1 - BACKUP PREFS
this will do the following:
Copy C:\Documents and Settings\%USERNAME%\Application Data\FileZilla
\sitemanager.xml
to this location: \\drake\pvt\%USERNAME%\FileZilla-Prefs\

BUTTON 2 - RESTORE PREFS
this will do the opposite:
copy sitemanager.xml file from: \\drake\pvt\%USERNAME%\FileZilla-Prefs
\ and put it here:
Copy C:\Documents and Settings\%USERNAME%\Application Data\FileZilla\

And I would like to to not prompt if files exists, just overwrite...

thanks
Like this thread about copying files by overwriting:
http://groups.google.com/group/micro...239d3c2?hl=en#

You can simply use,
My.Computer.Filesystem.CopyFile(sourcePath,destPat h,True)

...and make sure you have the right to copy to target UNC destination
not to get an exception like "access is denied".

For more info on detailed usage:
http://msdn.microsoft.com/en-us/libr...yf(VS.80).aspx

Hope this helps,

Onur Güzel
Sep 16 '08 #2

P: n/a
On Sep 16, 2:15*pm, Jason <paul...@excite.comwrote:
I want to create a simple program with Two buttons on the form.

BUTTON 1 - BACKUP PREFS
this will do the following:
Copy C:\Documents and Settings\%USERNAME%\Application Data\FileZilla
\sitemanager.xml
to this location: \\drake\pvt\%USERNAME%\FileZilla-Prefs\

BUTTON 2 - RESTORE PREFS
this will do the opposite:
copy sitemanager.xml file from: \\drake\pvt\%USERNAME%\FileZilla-Prefs
\ and put it here:
Copy C:\Documents and Settings\%USERNAME%\Application Data\FileZilla\

And I would like to to not prompt if files exists, just overwrite...

thanks
I would use the FIle Class in the System.I namespace. Specifically,
the File.Copy method with the overload that takes a third parameter, a
boolean that specifies to overwrite or not.
Sep 16 '08 #3

P: n/a
Here is what I tried:
My.Computer.FileSystem.CopyFile("c:\Documents and Settings\user
\Application Data\Adobe\InDesign\Version 5.0\InCopy TextMacros", _
"\\drake\home\user\text", True)

I get a: Could not complete operation since a directory already exists
in this path '\\drake\home\user\text'.

also how do I do a %username% variable in the path so it only works
for current user?
On Sep 16, 3:27*pm, za...@construction-imaging.com wrote:
On Sep 16, 2:15*pm, Jason <paul...@excite.comwrote:
I want to create a simple program with Two buttons on the form.
BUTTON 1 - BACKUP PREFS
this will do the following:
Copy C:\Documents and Settings\%USERNAME%\Application Data\FileZilla
\sitemanager.xml
to this location: \\drake\pvt\%USERNAME%\FileZilla-Prefs\
BUTTON 2 - RESTORE PREFS
this will do the opposite:
copy sitemanager.xml file from: \\drake\pvt\%USERNAME%\FileZilla-Prefs
\ and put it here:
Copy C:\Documents and Settings\%USERNAME%\Application Data\FileZilla\
And I would like to to not prompt if files exists, just overwrite...
thanks

I would use the FIle Class in the System.I namespace. Specifically,
the File.Copy method with the overload that takes a third parameter, a
boolean that specifies to overwrite or not.
Sep 16 '08 #4

P: n/a
"Jason" <pa*****@excite.comwrote in message
news:cf**********************************@f63g2000 hsf.googlegroups.com...
also how do I do a %username% variable in the path so it only works
for current user?
Isn't that automatic? Once the Filesystem takes over the OS handles the auth
based on the current user and not the App?

--
Phillip Windell
www.wandtv.com

The views expressed, are my own and not those of my employer, or Microsoft,
or anyone else associated with me, including my cats.
-----------------------------------------------------
Sep 16 '08 #5

P: n/a
On Sep 16, 11:07*pm, Jason <paul...@excite.comwrote:
Here is what I tried:
My.Computer.FileSystem.CopyFile("c:\Documents and Settings\user
\Application Data\Adobe\InDesign\Version 5.0\InCopy TextMacros", _
"\\drake\home\user\text", True)

I get a: Could not complete operation since a directory already exists
in this path '\\drake\home\user\text'.

also how do I do a %username% variable in the path so it only works
for current user?

On Sep 16, 3:27*pm, za...@construction-imaging.com wrote:
On Sep 16, 2:15*pm, Jason <paul...@excite.comwrote:
I want to create a simple program with Two buttons on the form.
BUTTON 1 - BACKUP PREFS
this will do the following:
Copy C:\Documents and Settings\%USERNAME%\Application Data\FileZilla
\sitemanager.xml
to this location: \\drake\pvt\%USERNAME%\FileZilla-Prefs\
BUTTON 2 - RESTORE PREFS
this will do the opposite:
copy sitemanager.xml file from: \\drake\pvt\%USERNAME%\FileZilla-Prefs
\ and put it here:
Copy C:\Documents and Settings\%USERNAME%\Application Data\FileZilla\
And I would like to to not prompt if files exists, just overwrite...
thanks
I would use the FIle Class in the System.I namespace. Specifically,
the File.Copy method with the overload that takes a third parameter, a
boolean that specifies to overwrite or not.- Hide quoted text -

- Show quoted text -
You're not specifying exact path of file,it seems you're trying to
copy folder with CopyFile function which is invalid, based on your
first post, you must include file name under the directory.
(sitemanager.xml).

My.Computer.FileSystem.CopyFile("C:\Documents and Settings\%USERNAME%
\Application Data\FileZilla
\sitemanager.xml","\\drake\home\user\text\sitemana ger.xml", True)

As the folder location in your last post is different than the one in
your first post, you can modify file location whatever you wish.

PS: If you intend to copy directories instead of file (had a suspicion
after your last post), you can use
"My.Computer.FileSystem.CopyDirectory":
http://msdn.microsoft.com/en-us/libr...5e(VS.80).aspx

Hope this helps,

Onur Güzel

Sep 16 '08 #6

P: n/a
I have more than one user under documents and settings\ and
%username% does not work...

On Sep 16, 4:22*pm, kimiraikkonen <kimiraikkone...@gmail.comwrote:
On Sep 16, 11:07*pm, Jason <paul...@excite.comwrote:
Here is what I tried:
My.Computer.FileSystem.CopyFile("c:\Documents and Settings\user
\Application Data\Adobe\InDesign\Version 5.0\InCopy TextMacros", _
"\\drake\home\user\text", True)
I get a: Could not complete operation since a directory already exists
in this path '\\drake\home\user\text'.
also how do I do a %username% variable in the path so it only works
for current user?
On Sep 16, 3:27*pm, za...@construction-imaging.com wrote:
On Sep 16, 2:15*pm, Jason <paul...@excite.comwrote:
I want to create a simple program with Two buttons on the form.
BUTTON 1 - BACKUP PREFS
this will do the following:
Copy C:\Documents and Settings\%USERNAME%\Application Data\FileZilla
\sitemanager.xml
to this location: \\drake\pvt\%USERNAME%\FileZilla-Prefs\
BUTTON 2 - RESTORE PREFS
this will do the opposite:
copy sitemanager.xml file from: \\drake\pvt\%USERNAME%\FileZilla-Prefs
\ and put it here:
Copy C:\Documents and Settings\%USERNAME%\Application Data\FileZilla\
And I would like to to not prompt if files exists, just overwrite....
thanks
I would use the FIle Class in the System.I namespace. Specifically,
the File.Copy method with the overload that takes a third parameter, a
boolean that specifies to overwrite or not.- Hide quoted text -
- Show quoted text -

You're not specifying exact path of file,it seems you're trying to
copy folder with CopyFile function which is invalid, based on your
first post, you must include file name under the directory.
(sitemanager.xml).

My.Computer.FileSystem.CopyFile("C:\Documents and Settings\%USERNAME%
\Application Data\FileZilla
\sitemanager.xml","\\drake\home\user\text\sitemana ger.xml", True)

As the folder location in your last post is different than the one in
your first post, you can modify file location whatever you wish.

PS: If you intend to copy directories instead of file (had a suspicion
after your last post), you can use
"My.Computer.FileSystem.CopyDirectory":http://msdn.microsoft.com/en-us/libr...5e(VS.80).aspx

Hope this helps,

Onur Güzel
Sep 16 '08 #7

P: n/a
You replace %USERNAME% in the text string with the actual name of the user's
folder.

Or is the problem that you don't know how to find out the name of the user's
folder?

"Jason" <pa*****@excite.comwrote in message
news:eb**********************************@l64g2000 hse.googlegroups.com...
I have more than one user under documents and settings\ and
%username% does not work...

On Sep 16, 4:22 pm, kimiraikkonen <kimiraikkone...@gmail.comwrote:
On Sep 16, 11:07 pm, Jason <paul...@excite.comwrote:
Here is what I tried:
My.Computer.FileSystem.CopyFile("c:\Documents and Settings\user
\Application Data\Adobe\InDesign\Version 5.0\InCopy TextMacros", _
"\\drake\home\user\text", True)
I get a: Could not complete operation since a directory already exists
in this path '\\drake\home\user\text'.
also how do I do a %username% variable in the path so it only works
for current user?
On Sep 16, 3:27 pm, za...@construction-imaging.com wrote:
On Sep 16, 2:15 pm, Jason <paul...@excite.comwrote:
I want to create a simple program with Two buttons on the form.
BUTTON 1 - BACKUP PREFS
this will do the following:
Copy C:\Documents and Settings\%USERNAME%\Application Data\FileZilla
\sitemanager.xml
to this location: \\drake\pvt\%USERNAME%\FileZilla-Prefs\
BUTTON 2 - RESTORE PREFS
this will do the opposite:
copy sitemanager.xml file from:
\\drake\pvt\%USERNAME%\FileZilla-Prefs
\ and put it here:
Copy C:\Documents and Settings\%USERNAME%\Application
Data\FileZilla\
And I would like to to not prompt if files exists, just overwrite...
thanks
I would use the FIle Class in the System.I namespace. Specifically,
the File.Copy method with the overload that takes a third parameter, a
boolean that specifies to overwrite or not.- Hide quoted text -
- Show quoted text -

You're not specifying exact path of file,it seems you're trying to
copy folder with CopyFile function which is invalid, based on your
first post, you must include file name under the directory.
(sitemanager.xml).

My.Computer.FileSystem.CopyFile("C:\Documents and Settings\%USERNAME%
\Application Data\FileZilla
\sitemanager.xml","\\drake\home\user\text\sitemana ger.xml", True)

As the folder location in your last post is different than the one in
your first post, you can modify file location whatever you wish.

PS: If you intend to copy directories instead of file (had a suspicion
after your last post), you can use
"My.Computer.FileSystem.CopyDirectory":http://msdn.microsoft.com/en-us/libr...5e(VS.80).aspx

Hope this helps,

Onur Güzel
Sep 16 '08 #8

P: n/a
I guess I dont know how to find it out...I mean there are more than
one person that will use a computer, but this app will be put in All
Users Desktop, so anyone can run it.

so I want it to work when user1 is logged in as well as when user2 is
logged in.
so it would need to know when to use:
c:\documents and settings\user1\Application Data
and
c:\documents and settings\user2\Application Data

based on the user that is logged in
On Sep 16, 7:21*pm, "James Hahn" <jh...@yahoo.comwrote:
You replace %USERNAME% in the text string with the actual name of the user's
folder.

Or is the problem that you don't know how to find out the name of the user's
folder?

"Jason" <paul...@excite.comwrote in message

news:eb**********************************@l64g2000 hse.googlegroups.com...
I have more than one user under documents and settings\ * *and
%username% does not work...

On Sep 16, 4:22 pm, kimiraikkonen <kimiraikkone...@gmail.comwrote:
On Sep 16, 11:07 pm, Jason <paul...@excite.comwrote:
Here is what I tried:
My.Computer.FileSystem.CopyFile("c:\Documents and Settings\user
\Application Data\Adobe\InDesign\Version 5.0\InCopy TextMacros", _
"\\drake\home\user\text", True)
I get a: Could not complete operation since a directory already exists
in this path '\\drake\home\user\text'.
also how do I do a %username% variable in the path so it only works
for current user?
On Sep 16, 3:27 pm, za...@construction-imaging.com wrote:
On Sep 16, 2:15 pm, Jason <paul...@excite.comwrote:
I want to create a simple program with Two buttons on the form.
BUTTON 1 - BACKUP PREFS
this will do the following:
Copy C:\Documents and Settings\%USERNAME%\Application Data\FileZilla
\sitemanager.xml
to this location: \\drake\pvt\%USERNAME%\FileZilla-Prefs\
BUTTON 2 - RESTORE PREFS
this will do the opposite:
copy sitemanager.xml file from:
\\drake\pvt\%USERNAME%\FileZilla-Prefs
\ and put it here:
Copy C:\Documents and Settings\%USERNAME%\Application
Data\FileZilla\
And I would like to to not prompt if files exists, just overwrite....
thanks
I would use the FIle Class in the System.I namespace. Specifically,
the File.Copy method with the overload that takes a third parameter, a
boolean that specifies to overwrite or not.- Hide quoted text -
- Show quoted text -
You're not specifying exact path of file,it seems you're trying to
copy folder with CopyFile function which is invalid, based on your
first post, you must include file name under the directory.
(sitemanager.xml).
My.Computer.FileSystem.CopyFile("C:\Documents and Settings\%USERNAME%
\Application Data\FileZilla
\sitemanager.xml","\\drake\home\user\text\sitemana ger.xml", True)
As the folder location in your last post is different than the one in
your first post, you can modify file location whatever you wish.
PS: If you intend to copy directories instead of file (had a suspicion
after your last post), you can use
"My.Computer.FileSystem.CopyDirectory":http://msdn.microsoft.com/en-us/libr...5e(VS.80).aspx
Hope this helps,
Onur Güzel
Sep 17 '08 #9

P: n/a
Have a look at the property Environment.UserName in the System namespace.

However, it might be simpler to use the Environment.GetFolderPath method
with the enumerated parameter MyDocuments.

"Jason" <pa*****@excite.comwrote in message
news:42**********************************@x35g2000 hsb.googlegroups.com...
I guess I dont know how to find it out...I mean there are more than
one person that will use a computer, but this app will be put in All
Users Desktop, so anyone can run it.

so I want it to work when user1 is logged in as well as when user2 is
logged in.
so it would need to know when to use:
c:\documents and settings\user1\Application Data
and
c:\documents and settings\user2\Application Data

based on the user that is logged in
On Sep 16, 7:21 pm, "James Hahn" <jh...@yahoo.comwrote:
You replace %USERNAME% in the text string with the actual name of the
user's
folder.

Or is the problem that you don't know how to find out the name of the
user's
folder?

"Jason" <paul...@excite.comwrote in message

news:eb**********************************@l64g2000 hse.googlegroups.com...
I have more than one user under documents and settings\ and
%username% does not work...

On Sep 16, 4:22 pm, kimiraikkonen <kimiraikkone...@gmail.comwrote:
On Sep 16, 11:07 pm, Jason <paul...@excite.comwrote:
Here is what I tried:
My.Computer.FileSystem.CopyFile("c:\Documents and Settings\user
\Application Data\Adobe\InDesign\Version 5.0\InCopy TextMacros", _
"\\drake\home\user\text", True)
I get a: Could not complete operation since a directory already exists
in this path '\\drake\home\user\text'.
also how do I do a %username% variable in the path so it only works
for current user?
On Sep 16, 3:27 pm, za...@construction-imaging.com wrote:
On Sep 16, 2:15 pm, Jason <paul...@excite.comwrote:
I want to create a simple program with Two buttons on the form.
BUTTON 1 - BACKUP PREFS
this will do the following:
Copy C:\Documents and Settings\%USERNAME%\Application
Data\FileZilla
\sitemanager.xml
to this location: \\drake\pvt\%USERNAME%\FileZilla-Prefs\
BUTTON 2 - RESTORE PREFS
this will do the opposite:
copy sitemanager.xml file from:
\\drake\pvt\%USERNAME%\FileZilla-Prefs
\ and put it here:
Copy C:\Documents and Settings\%USERNAME%\Application
Data\FileZilla\
And I would like to to not prompt if files exists, just
overwrite...
thanks
I would use the FIle Class in the System.I namespace. Specifically,
the File.Copy method with the overload that takes a third parameter,
a
boolean that specifies to overwrite or not.- Hide quoted text -
- Show quoted text -
You're not specifying exact path of file,it seems you're trying to
copy folder with CopyFile function which is invalid, based on your
first post, you must include file name under the directory.
(sitemanager.xml).
My.Computer.FileSystem.CopyFile("C:\Documents and Settings\%USERNAME%
\Application Data\FileZilla
\sitemanager.xml","\\drake\home\user\text\sitemana ger.xml", True)
As the folder location in your last post is different than the one in
your first post, you can modify file location whatever you wish.
PS: If you intend to copy directories instead of file (had a suspicion
after your last post), you can use
"My.Computer.FileSystem.CopyDirectory":http://msdn.microsoft.com/en-us/libr...5e(VS.80).aspx
Hope this helps,
Onur Güzel
Sep 17 '08 #10

P: n/a
In regards to obtaining the user name the example below shows how to get the
name via a routine under My.Computer namespace along with getting My
document path. This was done this way to be consistent plus when a user name
is returned on our Novell network the domain is added and is not wanted.

Dim UserName As String = ""
If My.Computer.PersonalFolder(UserName) Then
MsgBox(UserName & Environment.NewLine &
My.Computer.UserNameWithNoDomain)
End If

....
Partial Class MyComputer
''' <summary>
''' The name of the user's domain, or the computer name if no domain
is present.
''' </summary>
''' <value></value>
''' <returns></returns>
''' <remarks></remarks>
Public ReadOnly Property DomainName() As String
Get
Return SystemInformation.UserDomainName
End Get
End Property
''' <summary>
''' Used to return My.User.Name without domain name
''' </summary>
''' <value></value>
''' <returns></returns>
''' <remarks></remarks>
Public ReadOnly Property UserNameWithNoDomain() As String
Get
Return Strings.Replace(My.User.Name, My.Computer.DomainName &
"\", "")
End Get
End Property

''' <summary>
''' Safe method to return My Documents folder
''' </summary>
''' <param name="strPath"></param>
''' <returns>Path to My Documents</returns>
''' <remarks>
''' Users at DOR have network My Document folders were this adds a
little protection
''' to if the network is down and we query for the folder. Without
this we have no
''' idea if the directory is indeed available.
''' </remarks>
Public Function PersonalFolder(ByRef strPath As String) As Boolean
Try
If
IO.Directory.Exists(My.Computer.FileSystem.Special Directories.MyDocuments)
Then
strPath =
My.Computer.FileSystem.SpecialDirectories.MyDocume nts
Return True
Else
Return False
End If
Catch ex As Exception
Return False
End Try
End Function
End Class

"Jason" <pa*****@excite.comwrote in message
news:cf**********************************@f63g2000 hsf.googlegroups.com...
Here is what I tried:
My.Computer.FileSystem.CopyFile("c:\Documents and Settings\user
\Application Data\Adobe\InDesign\Version 5.0\InCopy TextMacros", _
"\\drake\home\user\text", True)

I get a: Could not complete operation since a directory already exists
in this path '\\drake\home\user\text'.

also how do I do a %username% variable in the path so it only works
for current user?
On Sep 16, 3:27 pm, za...@construction-imaging.com wrote:
On Sep 16, 2:15 pm, Jason <paul...@excite.comwrote:
I want to create a simple program with Two buttons on the form.
BUTTON 1 - BACKUP PREFS
this will do the following:
Copy C:\Documents and Settings\%USERNAME%\Application Data\FileZilla
\sitemanager.xml
to this location: \\drake\pvt\%USERNAME%\FileZilla-Prefs\
BUTTON 2 - RESTORE PREFS
this will do the opposite:
copy sitemanager.xml file from: \\drake\pvt\%USERNAME%\FileZilla-Prefs
\ and put it here:
Copy C:\Documents and Settings\%USERNAME%\Application Data\FileZilla\
And I would like to to not prompt if files exists, just overwrite...
thanks

I would use the FIle Class in the System.I namespace. Specifically,
the File.Copy method with the overload that takes a third parameter, a
boolean that specifies to overwrite or not.

Sep 17 '08 #11

This discussion thread is closed

Replies have been disabled for this discussion.