Click here to Skip to main content
15,881,742 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
sir ! i have written a code for driveinfo class but showing error.
the code is below:
C#
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;

namespace directoryinfo1
{
    public class demoimplement
    {
        public static void copyallfiles(DirectoryInfo source, DirectoryInfo target)
        {
            if (source.FullName.ToLower() == target.FullName.ToLower())
            {
                return;
            }
            if (Directory.Exists(target.FullName) == false)
            {
                Directory.CreateDirectory(target.FullName);
            }
            foreach (FileInfo fi in source.GetFiles())
            {
                Console.WriteLine(@"copying files {0}\{1}", target.FullName, fi.Name);
                fi.CopyTo(Path.Combine(target.ToString(), fi.Name), true);
            }
            foreach (DirectoryInfo disourcesubdir in source.GetDirectories())
            {
                DirectoryInfo nexttargetsubdir = target.CreateSubdirectory(disourcesubdir.Name);
                copyallfiles(disourcesubdir, nexttargetsubdir);
            }
        }
    }
    public class test
    {



        public static void Main(string[] args)
        {

            string sourcedirectory = @"D:\\c#";
            string targetDirectory = @"E:\\tushky";
            DirectoryInfo sourcedir = new DirectoryInfo(sourcedirectory);
            DirectoryInfo targetdir = new DirectoryInfo(targetDirectory);
            copyallfiles(sourcedir,targetdir);
            Console.ReadLine();
            
            
            




        }
    }
}

the error is:
Error	1	The name 'copyallfiles' does not exist in the current context.
Posted
Updated 5-Feb-14 6:40am
v2

C#
demoimplement.copyallfiles(sourcedir,targetdir);
 
Share this answer
 
Comments
tusharkaushik 5-Feb-14 14:07pm    
very very thx sir!
Karthik_Mahalingam 5-Feb-14 14:25pm    
welcome.
if it helps, pls mark it as answer.
You cannot call copyallfiles directly from the main method.
copyallfiles is a static method that is part of the demoimplement class.

Thus, you can either call demoimplement.copyallfiles(sourcedir,targetdir); instead of directly calling it.

Or else you could create an instance of demoimplement. No need to mark copyallfiles as static in this case.
 
Share this answer
 
v5
you have not inherited the demoimplement class to get access to the function copyallfiles


you have to inherit the class demoimplement to use use function copyallfiles
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900