Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
499 views
in Technique[技术] by (71.8m points)

c# identifier expected?

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 SettingsDubMy DocumentsHoN Updatesest";
    string destDir = @"C:GamesHoN";
    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 SettingsDubMy DocumentsHoN Updatesest"; // ERROR HERE
public string destDir = @"C:GamesHoN"; // ERROR HERE

private static void RecursiveCopy(origDir, destDir)
{
    Console.WriteLine("done");
    Console.ReadLine();
}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...