繁体中文
设为首页
加入收藏
当前位置:.Net技术首页 >> Windows开发 >> 老外编的程序(六)--目录操作

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

2004-10-01 08:26:10  作者:  来源:互联网  浏览次数:29  文字大小:【】【】【
简介:// 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 Syste...
关键字:老外 目录 程序

// 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);

}

}

责任编辑:admin
相关文章