Simple program to copy files? how to?

J

Jason

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
 
K

kimiraikkonen

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/micr.../browse_thread/thread/27aa06092239d3c2?hl=en#

You can simply use,
My.Computer.Filesystem.CopyFile(sourcePath,destPath,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/library/36xbexyf(VS.80).aspx

Hope this helps,

Onur Güzel
 
Z

zacks

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.
 
J

Jason

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?
 
P

Phillip Windell

Jason said:
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.
-----------------------------------------------------
 
K

kimiraikkonen

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?




- 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\sitemanager.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/library/2swy9y5e(VS.80).aspx

Hope this helps,

Onur Güzel
 
J

Jason

I have more than one user under documents and settings\ and
%username% does not work...
 
J

James Hahn

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?

I have more than one user under documents and settings\ and
%username% does not work...
 
J

Jason

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
 
J

James Hahn

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.

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
 
K

Kevin S Gallagher

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.SpecialDirectories.MyDocuments)
Then
strPath =
My.Computer.FileSystem.SpecialDirectories.MyDocuments
Return True
Else
Return False
End If
Catch ex As Exception
Return False
End Try
End Function
End Class



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?
 

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