skipping files that wont copy?

[b][red]This message was edited by jboul99 at 2005-3-31 9:55:48[/red][/b][hr]
im trying to make a copy program that will copy files from a source to a destination but i cant seem to figure out how to skip a file that is lets say corrupt or in use. anyway heres what i have
public static void copyDirectory( string Src,string Dst )
{
try
{
String[] Files;

if( Dst[Dst.Length-1] != Path.DirectorySeparatorChar )
Dst+=Path.DirectorySeparatorChar;

if( !Directory.Exists(Dst) )
Directory.CreateDirectory(Dst);

Files=Directory.GetFileSystemEntries(Src);



foreach( string Element in Files )
{

if( Directory.Exists(Element) )
{
copyDirectory( Element,Dst+Path.GetFileName(Element) );

}
else if ( overwriteChkBox.CheckState == CheckState.Checked )
{
File.Copy( Element,Dst+Path.GetFileName(Element),true );
}
else
{
DialogResult errormsg =
MessageBox.Show(null, "The file being copied already exists. Please make sure overwriting files is enabled and try again.",
"File Exists :", MessageBoxButtons.OK );
}
}
}
catch
{
//im thinking i have to add the code here to skip a file but im unsure.
}
}



Thanks in advance!


Comments

  • [code]
    foreach(file in filelist) // or wathever you like
    {
    try
    {
    //code to copy a file
    }
    catch
    {
    }
    }
    [/code]

    This would make it skip a file.
    [hr]
    El PROgrammador Niklas Ulvinge
    (who doesn't know how to spell in inglish)

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

In this Discussion