473,396 Members | 1,892 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Simple program to copy files? how to?

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
10 4932
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
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
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
"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
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
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

44
by: Xah Lee | last post by:
here's a large exercise that uses what we built before. suppose you have tens of thousands of files in various directories. Some of these files are identical, but you don't know which ones are...
5
by: Ryan Waye | last post by:
I have looked extensively, and I have been unable to find commands that allow a C++ program to manipulate other files. How do I make C++ do simple things like copy and past files, and navigate...
5
by: Rob Somers | last post by:
Hey all I am writing a program to keep track of expenses and so on - it is not a school project, I am learning C as a hobby - At any rate, I am new to structs and reading and writing to files,...
10
by: serge calderara | last post by:
Dear all, I need to build a web application which will contains articles (long or short) I was wondering on what is the correct way to retrive those article on web page. In orther words, when...
23
by: Marco | last post by:
Could anyone please tell me why the program has the following error? I copy the program from http://www.beyondlogic.org/parlcd/parlcd.htm ...
6
by: Jim M | last post by:
I've been distributing a fairly mature, very specific MS Access application to end users in small offices of colleges for several years now. This is a part-time venture and low volume operation-...
10
true911m
by: true911m | last post by:
This is a simple walkthrough to get PyInstaller up and running. I decided to give PI a try, because it claims to be more selective about what it bundles into its executable files by default, and...
30
by: galiorenye | last post by:
Hi, Given this code: A** ppA = new A*; A *pA = NULL; for(int i = 0; i < 10; ++i) { pA = ppA; //do something with pA
5
by: =?Utf-8?B?SmFwZQ==?= | last post by:
im writing a c# console application that copies files chosen from the windows explorer. I chose the files i want to copy and then from the (right key) menu chose my program. the program starts...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.