欢迎光临
我们一直在努力

老外编的程序(六)--目录操作-.NET教程,Windows开发

建站超值云服务器,限时71元/月

// takes an array of file names or directory names on the command line.  
// determines what kind of name it is and processes it appropriately

using system;
using system.io;
using system.collections;

public class recursivefileprocessor {
    public static void main(string[] args) {
        foreach(string path in args) {
            if(file.exists(path)) {
                // this path is a file
                processfile(path);
            }               
            else if(directory.exists(path)) {
                // this path is a directory
                processdirectory(path);
            }
            else {
                console.writeline("{0} is not a valid file or directory.", path);
            }        
        }        
    }

    // process all files in the directory passed in, and recurse on any directories
    // that are found to process the files they contain
    public static void processdirectory(string targetdirectory) {
        // process the list of files found in the directory
        string [] fileentries = directory.getfiles(targetdirectory);
        foreach(string filename in fileentries)
            processfile(filename);

        // recurse into subdirectories of this directory
        string [] subdirectoryentries = directory.getdirectories(targetdirectory);
        foreach(string subdirectory in subdirectoryentries)
            processdirectory(subdirectory);
    }
        
    // real logic for processing found files would go here.
    public static void processfile(string path) {
        console.writeline("processed file {0}.", path);        
    }
}

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » 老外编的程序(六)--目录操作-.NET教程,Windows开发
分享到: 更多 (0)