C#使用Directoryinfo类获得目录信息和属性的方法
程序员文章站
2022-07-22 20:06:09
本文实例讲述了c#使用directoryinfo类获得目录信息和属性的方法。分享给大家供大家参考。具体如下:
using system;
using syste...
本文实例讲述了c#使用directoryinfo类获得目录信息和属性的方法。分享给大家供大家参考。具体如下:
using system; using system.io; class mainclass { static void main(string[] args) { fileinfo file = new fileinfo("c:\\a.txt"); // display directory information. directoryinfo dir = file.directory; console.writeline("checking directory: " + dir.name); console.writeline("in directory: " + dir.name); console.write("directory exists: "); console.writeline(dir.exists.tostring()); if (dir.exists) { console.write("directory created: "); console.writeline(dir.creationtime.tostring()); console.write("directory last updated: "); console.writeline(dir.lastwritetime.tostring()); console.write("directory last accessed: "); console.writeline(dir.lastaccesstime.tostring()); console.write("directory attribute list: "); console.writeline(dir.attributes.tostring()); console.writeline("directory contains: " + dir.getfiles().length.tostring() + " files"); } console.writeline(); } }
希望本文所述对大家的c#程序设计有所帮助。