上面是我的数据库结构,我想求得指定文件夹下(包括子文件夹)所有文件的大小。ASP。NET(C#)
求算法
DirID 文件夹或文件编号 ParentID 父目录ID Contain 文件大小 Flag 是否为文件夹在线等 急
解决方案 »
- sqlhelper 与 DbHelper与 Enterprise Library 都是什么?之间有什么关系?有什么区别?适合什么场所
- session("UnitName")=request.Form("select2")报缺少对象‘request’
- 因为安全原因,此 XML 文档中禁用 DTD因为安全原因?
- 有关从Request中取出对象的问题
- 查找 两个时间的比较差函数后用datatalbe装起来.但到前台不知如何调用?
- 求项目相关视频
- 如何为动态table添加onmouseover,onmouseout事件???
- 当用户输入的属性无效时,我怎么出来哪个无效属性的提示框。(自定义控件)
- str!=null与str!=string.Empty有什么区别
- 我想用VB.NET写一个html编辑器,请各位高手推荐好的资料或程序给我,在下感激不尽!
- 关于在网页中调用exe程序的问题...
- iframe如何使用?
2.然后用递归的方法检索每条记录;如果该记录的父目录为dirid且另行为文件则指定目录的容量增加该文件的大小
3.如果为文件夹则循环执行2
{
FileOrFolders = d.GetFileOrFolders();
foreach( FileOrFolder fof in FileOrFolders )
{
if( fof is File )
You Found a file;
else if ( fof is Directory )
FindFile( fof );
}
} 利用这段功能相似的代码,相信可以解决你的问题!
using System.IO;class Test
{
public static void Main()
{
// Specify the directories you want to manipulate.
string path = @"c:\MyDir";
string target = @"c:\TestDir"; try
{
// Determine whether the directory exists.
if (!Directory.Exists(path))
{
// Create the directory it does not exist.
Directory.CreateDirectory(path);
} if (Directory.Exists(target))
{
// Delete the target to ensure it is not there.
Directory.Delete(target, true);
} // Move the directory.
Directory.Move(path, target); // Create a file in the directory.
File.CreateText(target + @"\myfile.txt"); // Count the files in the target directory.
Console.WriteLine("The number of files in {0} is {1}",
target, Directory.GetFiles(target).Length);
}
catch (Exception e)
{
Console.WriteLine("The process failed: {0}", e.ToString());
}
finally {}
}
}
// For Directory.GetFiles and Directory.GetDirectories
// For File.Exists, Directory.Exists
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, recurse on any directories
// that are found, and 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);
} // Insert logic for processing found files here.
public static void ProcessFile(string path)
{
Console.WriteLine("Processed file '{0}'.", path);
}
}