|
-
Sep 14th, 2005, 03:48 PM
#1
Thread Starter
Hyperactive Member
Copy files that exist
I want to write an app that copies files from one directory to another, but only copies files that already exist in the to directory, overwrite them.
Any ideas?
-
Sep 14th, 2005, 06:09 PM
#2
Re: Copy files that exist
you want to copy files to another directory, but only if they already exist in that ' other ' directory ? so basically you want to write over them?
you can use the System.IO.File.Exists function for this.
VB Code:
Dim files As String() = IO.Directory.GetFiles("C:\Documents and Settings\den\My Documents\My Pictures")
For Each s As String In files
Dim fileinf As New IO.FileInfo(s)
Dim otherpath As String = "C:\" & fileinf.Name
If IO.File.Exists(otherpath) Then
IO.File.Copy(s, otherpath, True)
End If
Next
~
if a post is resolved, please mark it as [Resolved]
protected string get_Signature(){return Censored;}
[vbcode][php] please use code tags when posting any code [/php][/vbcode]
-
Sep 14th, 2005, 06:20 PM
#3
Re: Copy files that exist
in C#
Code:
string[] files = System.IO.Directory.GetFiles(@"C:\Documents and Settings\den\My Documents\My Pictures");
foreach(string s in files)
{
System.IO.FileInfo fileinf = new System.IO.FileInfo(s);
string otherpath = @"C:\" + fileinf.Name;
if ( IO.File.Exists(otherpath) )
{
System.IO.File.Copy(s, otherpath, true);
}
~
if a post is resolved, please mark it as [Resolved]
protected string get_Signature(){return Censored;}
[vbcode][php] please use code tags when posting any code [/php][/vbcode]
-
Sep 15th, 2005, 06:29 AM
#4
Thread Starter
Hyperactive Member
Re: Copy files that exist
Thanks, easy when you know how.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|