Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

c# identifier expected?

Tags:

c#

I am trying to create a program to copy all the files from one directory to another. But I am running in a basic issue. It says indentifier expected when I try to compile on line 52.

public bool RecursiveCopy()
{
    string origDir = @"D:\Documents and Settings\Dub\My Documents\HoN Updates\test";
    string destDir = @"C:\Games\HoN";
    bool status = false;

    //get all the info about the original directory
    var dirInfo = new DirectoryInfo(origDir);

    //retrieve all the _fileNames in the original directory
    var files = dirInfo.GetFiles(origDir);

    //always use a try...catch to deal 
    //with any exceptions that may occur
    try
    {
        //loop through all the file names and copy them
        foreach (string file in Directory.GetFiles(origDir))
        {
            var origFile = new FileInfo(file);
            var destFile = new FileInfo(file.Replace(origDir, destDir));

            //copy the file, use the OverWrite overload to overwrite
            //destination file if it exists

            System.IO.File.Copy(origFile.FullName, destFile.FullName, true);

            //TODO: If you dont want to remove the original
            //_fileNames comment this line out
            File.Delete(origFile.FullName);
            status = true;
        }
        Console.WriteLine("All files in " + origDir + " copied successfully!");
    }
    catch (Exception ex)
    {
        status = false;

        //handle any errors that may have occurred
        Console.WriteLine(ex.Message);
    }
    return status;
}

public string origDir = @"D:\Documents and Settings\Dub\My Documents\HoN Updates\test"; // ERROR HERE
public string destDir = @"C:\Games\HoN"; // ERROR HERE

private static void RecursiveCopy(origDir, destDir)
{
    Console.WriteLine("done");
    Console.ReadLine();
}
like image 975
Steven Avatar asked Aug 04 '09 00:08

Steven


3 Answers

You did not give type identifiers to your argument list here

static void RecursiveCopy(origDir, destDir)

should be

static void RecursiveCopy(string origDir, string destDir)
like image 168
Ed S. Avatar answered Sep 21 '22 18:09

Ed S.


Your method RecursiveCopy has two parameters listed without their types. It should be this:

static void RecursiveCopy(string origDir, string destDir)
like image 23
Sam Harwell Avatar answered Sep 17 '22 18:09

Sam Harwell


Here is your problem:

static void RecursiveCopy(origDir, destDir)

You don't specify the types for the parameters, perhaps you intended the following:

static void RecursiveCopy(string origDir, string destDir)

There are more issues however that I've noticed. It's possible you're still working on these, but from what you've posted:

  • You never call your RecursiveCopy method. Perhaps you meant to call it from Main() instead of declaring an overload with two parameters?

  • You declare two public fields origDir and destDir but then never use them. Instead you create two local variables in RecursiveCopy() and use these instead. Did you intend to create parameters or use the public fields instead?

  • Your copy is not actually true to its name of "recursive".

like image 44
lc. Avatar answered Sep 20 '22 18:09

lc.