老外编的程序(六)--目录操作

作者:袖梨 2022-07-02
// 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

相关文章

精彩推荐