本文整理汇总了C#中System.IO.DirectoryInfo类的典型用法代码示例。如果您正苦于以下问题:C# System.IO.DirectoryInfo类的具体用法?C# System.IO.DirectoryInfo怎么用?C# System.IO.DirectoryInfo使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
System.IO.DirectoryInfo类属于命名空间,在下文中一共展示了System.IO.DirectoryInfo类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: GetList
public static PrefSound[] GetList(bool allowDefault)
{
List<PrefSound> list = new List<PrefSound>();
if (allowDefault) list.Add(Default);
list.Add(None);
// read available sounds from C:\WINDOWS\Media
string systemPath = Environment.GetFolderPath(Environment.SpecialFolder.System);
string windowsPath = System.IO.Path.GetDirectoryName(systemPath);
string mediaPath = System.IO.Path.Combine(windowsPath, "Media");
if (System.IO.Directory.Exists(mediaPath))
{
System.IO.DirectoryInfo d = new System.IO.DirectoryInfo(mediaPath);
System.IO.FileInfo[] files = d.GetFiles("*.wav");
foreach (System.IO.FileInfo file in files)
{
PrefSound ps = new PrefSound(true, file.Name, file.FullName);
list.Add(ps);
}
}
PrefSound[] arr = list.ToArray();
list.Clear();
list = null;
return arr;
}
开发者ID:jalsco,项目名称:growl-for-windows-branched,代码行数:26,代码来源:PrefSound.cs
示例2: GetLargestFilePathFromDir
public static string GetLargestFilePathFromDir(string startFolder)
{
// Take a snapshot of the file system.
System.IO.DirectoryInfo dir = new System.IO.DirectoryInfo(startFolder);
// This method assumes that the application has discovery permissions
// for all folders under the specified path.
IEnumerable<System.IO.FileInfo> fileList = dir.GetFiles("*.*", System.IO.SearchOption.AllDirectories);
//Return the size of the largest file
long maxSize =
(from file in fileList
let len = GetFileLength(file)
select len)
.Max();
Console.WriteLine("The length of the largest file under {0} is {1}", startFolder, maxSize);
// Return the FileInfo object for the largest file
// by sorting and selecting from beginning of list
System.IO.FileInfo longestFile =
(from file in fileList
let len = GetFileLength(file)
where len > 0
orderby len descending
select file)
.First();
Console.WriteLine("The largest file under {0} is {1} with a length of {2} bytes",
startFolder, longestFile.FullName, longestFile.Length);
return longestFile.FullName;
}
开发者ID:a253560600,项目名称:tdmaker,代码行数:33,代码来源:FileSystemHelper.cs
示例3: XCopy
/// for an example:XCopy("c:\a\", "d:\b\");
/// <summary>Copy source script to report folder</summary>
/// <param name="sourceDir">sourceDir</param>
/// <param name="targetDir">targetDir</param>
public static void XCopy(string sourceDir, string targetDir)
{
//If the source directory exists.
if (System.IO.Directory.Exists(sourceDir))
{
//If the source directory does not exist, create it.
if (!System.IO.Directory.Exists(targetDir))
System.IO.Directory.CreateDirectory(targetDir);
//Get data from sourcedir.
System.IO.DirectoryInfo sourceInfo = new System.IO.DirectoryInfo(sourceDir);
//Copy the files.
System.IO.FileInfo[] files = sourceInfo.GetFiles();
foreach (System.IO.FileInfo file in files)
{
System.IO.File.Copy(sourceDir + "\\" + file.Name, targetDir + "\\" + file.Name, true);
}
//Copy the dir.
System.IO.DirectoryInfo[] dirs = sourceInfo.GetDirectories();
foreach (System.IO.DirectoryInfo dir in dirs)
{
string currentSource = dir.FullName;
string currentTarget = dir.FullName.Replace(sourceDir, targetDir);
System.IO.Directory.CreateDirectory(currentTarget);
//recursion
XCopy(currentSource, currentTarget);
}
}
}
开发者ID:YouwenYao,项目名称:NformTestMain,代码行数:33,代码来源:TestCaseDriver.cs
示例4: getFiles
private System.Collections.Generic.List<string> getFiles(string location, bool recursive)
{
System.Collections.Generic.List<string> sc = new List<string>();
System.IO.FileInfo fi = new System.IO.FileInfo(location);
if(fi.Exists)
{
sc.Add(fi.FullName);
return sc;
}
System.IO.DirectoryInfo di = new System.IO.DirectoryInfo(location);
if(di.Exists)
{
foreach(System.IO.FileInfo f in di.GetFiles())
{
foreach(string s in getFiles(f.FullName,recursive))
sc.Add(s);
}
if(recursive)
{
foreach(System.IO.DirectoryInfo d in di.GetDirectories())
{
foreach(string s in getFiles(d.FullName,recursive))
sc.Add(s);
}
}
}
return sc;
}
开发者ID:joshuaphendrix,项目名称:Imagizer,代码行数:34,代码来源:Form1.cs
示例5: xInfoElement
public xInfoElement()
{
g_Singleton = this;
InitializeComponent();
eCArchiveFile E = new eCArchiveFile(FileManager.GetFile("compiled_infos.bin"));
E.Position = 14;
eCDocArchive D = new eCDocArchive(E);
foreach (bCAccessorPropertyObject o in D)
{
InfoWrapper w = new InfoWrapper(o.Class as gCInfo);
m_pData.Add(w.Name.pString, w);
}
System.IO.DirectoryInfo m = new System.IO.DirectoryInfo(FileManager.g_pGamepath + "data\\raw\\infos");
if (m.Exists)
{
foreach (System.IO.FileInfo fi in m.GetFiles("*.xinf"))
{
InfoWrapper w = InfoWrapper.FromXml(System.Xml.Linq.XElement.Load(fi.FullName));
m_pData.Add(w.Name.pString, w);
}
}
listView1.ItemsSource = m_pData.Values;
setElement(m_pData["PANKRATZX2_00647"], 1, 0);
}
开发者ID:hhergeth,项目名称:RisenEditor,代码行数:28,代码来源:xInfoElement.xaml.cs
示例6: CleanUpTempFolder
private void CleanUpTempFolder()
{
try {
if (!Globals.IsTempCleanUpDone) {
Globals.IsTempCleanUpDone = true;
string baseReportPath = Server.MapPath("~/PDF");
//====================================================
// Clean up all old files in PDF folder
//====================================================
System.IO.DirectoryInfo pdfDir = new System.IO.DirectoryInfo(baseReportPath);
DateTime minDate = DateTime.Now.AddMinutes(-10);
System.IO.FileInfo[] pdfFiles = pdfDir.GetFiles("*.*");
foreach (System.IO.FileInfo fi in pdfFiles) {
if (fi.CreationTime < minDate) {
System.IO.File.Delete(fi.FullName);
}
}
}
}
catch {
// IGNORE ERRORS !
}
}
开发者ID:jwebb-vtg,项目名称:WSCIEMP,代码行数:27,代码来源:ShsHome.aspx.cs
示例7: DirectoryCheck
private void DirectoryCheck(String userName)
{
var receiptImageDir = new System.IO.DirectoryInfo(Server.MapPath("~/IMG/"));
if (!receiptImageDir.Exists)
{
var createReceiptImageDir = new System.IO.DirectoryInfo(Server.MapPath("~"));
createReceiptImageDir.CreateSubdirectory("IMG/");
}
receiptImageDir = new System.IO.DirectoryInfo(Server.MapPath("~/IMG/receiptImage/"));
if (!receiptImageDir.Exists)
{
var createReceiptImageDir = new System.IO.DirectoryInfo(Server.MapPath("~/IMG"));
createReceiptImageDir.CreateSubdirectory("receiptImage/");
}
receiptImageDir = new System.IO.DirectoryInfo(Server.MapPath("~/IMG/receiptImage/"
+ userName + "/"));
if (!receiptImageDir.Exists)
{
var createReceiptImageDir = new System.IO.DirectoryInfo(Server.MapPath("~/IMG/receiptImage/"));
createReceiptImageDir.CreateSubdirectory(userName + "/");
}
}
开发者ID:jrxFive,项目名称:E-Receipt,代码行数:27,代码来源:About.aspx.cs
示例8: GetChildItems
protected override void GetChildItems(string path, bool recurse)
{
if (string.IsNullOrEmpty(path))
{
throw new Exception("Path can't be empty");
}
path = NormalizePath(path);
System.IO.DirectoryInfo directory = new System.IO.DirectoryInfo(path);
if (directory.Exists)
{
GetDirectoryContent(directory, recurse);
}
else
{
System.IO.FileInfo item = new System.IO.FileInfo(path);
if (item.Exists)
{
if ((item.Attributes & System.IO.FileAttributes.Hidden) == 0)
{
WriteItemObject(item, path, false);
}
}
else
{
Exception exception = new System.IO.IOException("Path doesn't exist: " + path);
WriteError(new ErrorRecord(exception, "ItemDoesNotExist", ErrorCategory.ObjectNotFound, path));
}
}
}
开发者ID:mauve,项目名称:Pash,代码行数:31,代码来源:FileSystemProvider.cs
示例9: backup
public static void backup()
{
//verificar se existem mais de 10 backups e deletar os mais antigos
System.IO.DirectoryInfo dirInfo = new System.IO.DirectoryInfo(appDir + "\\backup");
while (dirInfo.GetFiles().Length > 5)
{
System.IO.FileInfo tmp = dirInfo.GetFiles()[0];
foreach (System.IO.FileInfo file in dirInfo.GetFiles())
{
if (tmp.CreationTime < file.CreationTime)
{
tmp = file;
}
}
tmp.Delete();
}
ZipFile zip =
new ZipFile(Library.appDir + "\\backup\\" +
DateTime.Now.Day + DateTime.Now.Month + DateTime.Now.Year +
DateTime.Now.Hour + DateTime.Now.Minute + DateTime.Now.Second);
zip.CompressionLevel = Ionic.Zlib.CompressionLevel.BestCompression;
zip.AddFile(Library.appDir + "\\db\\cipdatabase.sdf");
zip.Save();
}
开发者ID:alphaman8,项目名称:CIP_beta1,代码行数:26,代码来源:Library.cs
示例10: GetFiles
public List<FileNames> GetFiles()
{
List<FileNames> listFiles = new List<FileNames>();
System.IO.DirectoryInfo directoryInfo = new System.IO.DirectoryInfo(HostingEnvironment.MapPath("~/App_Data/UploadedFiles"));
int i = 0;
foreach (var item in directoryInfo.GetFiles())
{
FileNames file = new FileNames();
file.FileID = i + 1;
file.FileName = item.Name;
file.FilePath = directoryInfo.FullName + @"\" + item.Name;
string mimeType = "application/unknown";
//string ext = System.IO.Path.GetExtension(item).ToLower();
Microsoft.Win32.RegistryKey regKey = Microsoft.Win32.Registry.ClassesRoot.OpenSubKey(item.Extension);
//if (regKey != null && regKey.GetValue("Content Type") != null)
mimeType = regKey.GetValue("Content Type").ToString();
//return mimeType;
file.FileContentType = mimeType;
file.FileByte = System.IO.File.ReadAllBytes(file.FilePath);
listFiles.Add(file);
i = i + 1;
}
return listFiles;
}
开发者ID:bclark00,项目名称:klmnscamp,代码行数:27,代码来源:DownloadModel.cs
示例11: GetSerialPorts
public static List<string> GetSerialPorts()
{
List<string> result = new List<string>();
try {
System.IO.DirectoryInfo di = new System.IO.DirectoryInfo("/dev");
System.IO.FileInfo[] fi = di.GetFiles("ttyUSB*");
foreach (System.IO.FileInfo f in fi) {
result.Add(f.FullName);
}
} catch (Exception) {
//eh
}
try {
String[] ports = SerialPort.GetPortNames();
foreach (String p in ports) {
result.Add(p);
}
} catch (Exception) {
//eh
}
return result;
}
开发者ID:afaucher,项目名称:LazerTagHost,代码行数:25,代码来源:LazerTagSerial.cs
示例12: BindData
private void BindData()
{
using(DataTable dt = new DataTable("Files"))
{
dt.Columns.Add("FileID",typeof(long));
dt.Columns.Add("FileName",typeof(string));
dt.Columns.Add("Description",typeof(string));
DataRow dr = dt.NewRow();
dr["FileID"] = 0;
dr["FileName"] = "../spacer.gif"; // use blank.gif for Description Entry
dr["Description"] = "Select Rank Image";
dt.Rows.Add(dr);
System.IO.DirectoryInfo dir = new System.IO.DirectoryInfo(Request.MapPath(String.Format("{0}images/ranks",Data.ForumRoot)));
System.IO.FileInfo[] files = dir.GetFiles("*.*");
long nFileID = 1;
foreach(System.IO.FileInfo file in files)
{
string sExt = file.Extension.ToLower();
if(sExt!=".gif" && sExt!=".gif" && sExt!=".jpg")
continue;
dr = dt.NewRow();
dr["FileID"] = nFileID++;
dr["FileName"] = file.Name;
dr["Description"] = file.Name;
dt.Rows.Add(dr);
}
RankImage.DataSource = dt;
RankImage.DataValueField = "FileName";
RankImage.DataTextField = "Description";
}
DataBind();
}
开发者ID:zi-yu,项目名称:orionsbelt,代码行数:35,代码来源:editrank.ascx.cs
示例13: CanQueryLuceneIndexCreatedOnDisk
public void CanQueryLuceneIndexCreatedOnDisk()
{
CanCreateLuceneIndexOnDisk();
System.IO.DirectoryInfo di = new System.IO.DirectoryInfo(System.IO.Path.GetTempPath());
using (Lucene.Net.Store.Directory directory = Lucene.Net.Store.FSDirectory.Open(di))
{
Lucene.Net.Index.IndexReader ir = Lucene.Net.Index.IndexReader.Open(directory, true);
Lucene.Net.Search.Searcher searcher = new Lucene.Net.Search.IndexSearcher(ir);
using (Lucene.Net.Analysis.Analyzer analyzer = new Lucene.Net.Analysis.Standard.StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_30))
{
Lucene.Net.QueryParsers.QueryParser parser = new Lucene.Net.QueryParsers.QueryParser(Version.LUCENE_30, "content", analyzer);
Lucene.Net.Search.Query query = parser.Parse("lorem");
Lucene.Net.Search.TopScoreDocCollector collector = Lucene.Net.Search.TopScoreDocCollector.Create(100, true);
searcher.Search(query, collector);
Lucene.Net.Search.ScoreDoc[] docs = collector.TopDocs().ScoreDocs;
foreach (Lucene.Net.Search.ScoreDoc scoreDoc in docs)
{
//Get the document that represents the search result.
Document document = searcher.Doc(scoreDoc.Doc);
var id = document.Get("Id");
var content = document.Get("content");
}
}
}
}
开发者ID:ThomasSchmidt,项目名称:MixedStuff,代码行数:28,代码来源:LuceneTests.cs
示例14: BindData
private void BindData()
{
using ( DataTable dt = new DataTable( "Files" ) )
{
dt.Columns.Add( "FileID", typeof( long ) );
dt.Columns.Add( "FileName", typeof( string ) );
DataRow dr = dt.NewRow();
dr ["FileID"] = 0;
dr ["FileName"] = "Select File (*.pak)";
dt.Rows.Add( dr );
System.IO.DirectoryInfo dir = new System.IO.DirectoryInfo( Request.MapPath( String.Format( "{0}images/emoticons", YafForumInfo.ForumFileRoot ) ) );
System.IO.FileInfo [] files = dir.GetFiles( "*.pak" );
long nFileID = 1;
foreach ( System.IO.FileInfo file in files )
{
dr = dt.NewRow();
dr ["FileID"] = nFileID++;
dr ["FileName"] = file.Name;
dt.Rows.Add( dr );
}
File.DataSource = dt;
File.DataValueField = "FileID";
File.DataTextField = "FileName";
}
DataBind();
}
开发者ID:coredweller,项目名称:PhishMarket,代码行数:28,代码来源:smilies_import.ascx.cs
示例15: button1_Click
private void button1_Click(object sender, EventArgs e)
{
System.IO.DirectoryInfo dropFolder = new System.IO.DirectoryInfo(@"\\cob-hds-1\compression\QC\");
photographer.snapShot(dropFolder);
}
开发者ID:BagpipesJohnson,项目名称:QualityControl,代码行数:7,代码来源:OverSeer.cs
示例16: backupSSF
public static void backupSSF()
{
//verifica se existe o diretório, caso não exista será criado
string dirAnteriores = Library.appDir + "\\ssf\\anteriores\\";
if (!System.IO.Directory.Exists(dirAnteriores))
{
System.IO.Directory.CreateDirectory(dirAnteriores);
}
//verifica se existe o diretório, caso não exista será criado
string dirZipados = Library.appDir + "\\ssf\\zipados\\";
if (!System.IO.Directory.Exists(dirZipados))
{
System.IO.Directory.CreateDirectory(dirZipados);
}
//backup ssf
System.IO.DirectoryInfo dirSSF = new System.IO.DirectoryInfo(appDir + "\\ssf");
string[] filePaths = System.IO.Directory.GetFiles(dirSSF.ToString(), "*.ssf");
ZipFile zip =
new ZipFile(dirZipados + DateTime.Now.Day + DateTime.Now.Month + DateTime.Now.Year +
DateTime.Now.Hour + DateTime.Now.Minute + DateTime.Now.Second + ".zip");
zip.CompressionLevel = Ionic.Zlib.CompressionLevel.BestCompression;
zip.AddFiles(filePaths);
zip.Save();
//move todos os arquivos
foreach (string file in filePaths)
System.IO.File.Move(file, dirAnteriores + System.IO.Path.GetFileName(file));
}
开发者ID:alphaman8,项目名称:CIP_beta1,代码行数:32,代码来源:Library.cs
示例17: btnSave_Click
private void btnSave_Click(object sender, EventArgs e)
{
string pathToFile = inputPath.Text; //pega o caminho do arquivo/programa do campo
string nameApp = inputName.Text; //pega o nome do arquivo/programa do campo
string[] files = {pathToFile, nameApp}; //seta o caminho e nome do arquivo/programa num array
string path = @"C:\\Users\\" + System.Environment.UserName + "\\Documents\\CentralAtalhos"; //seta o caminho para o arquivo de configuração
System.IO.DirectoryInfo directory = new System.IO.DirectoryInfo(path); //classe de informações de diretório
//verifica se diretório não existe
if (!directory.Exists)
{
System.IO.Directory.CreateDirectory(path); //cria diretório caso não exista
}
//Classe para criar o arquivo de configuração caso não exista e escrita no mesmo
using (System.IO.StreamWriter file =
new System.IO.StreamWriter(path + "\\atalhos.txt", true))
{
for (int i = 0; i < files.Length; i++)
{
file.WriteLine(files[i]); //escreve o array no arquivo de configuração
}
}
MessageBox.Show("Cadastrado com sucesso!", "Sucesso!", MessageBoxButtons.OK, MessageBoxIcon.Information);
this.Close();
}
开发者ID:brunogiovanni,项目名称:centralAtalhos,代码行数:27,代码来源:novoAtalho.cs
示例18: BindData
private void BindData()
{
using ( DataTable dt = new DataTable( "Files" ) )
{
dt.Columns.Add( "FileID", typeof( long ) );
dt.Columns.Add( "FileName", typeof( string ) );
dt.Columns.Add( "Description", typeof( string ) );
DataRow dr = dt.NewRow();
dr ["FileID"] = 0;
dr ["FileName"] = "../spacer.gif"; // use blank.gif for Description Entry
dr ["Description"] = "Select Smiley Image";
dt.Rows.Add( dr );
System.IO.DirectoryInfo dir = new System.IO.DirectoryInfo( Request.MapPath( String.Format( "{0}images/emoticons", YafForumInfo.ForumFileRoot ) ) );
System.IO.FileInfo [] files = dir.GetFiles( "*.*" );
long nFileID = 1;
foreach ( System.IO.FileInfo file in files )
{
string sExt = file.Extension.ToLower();
if ( sExt != ".png" && sExt != ".gif" && sExt != ".jpg" )
continue;
dr = dt.NewRow();
dr ["FileID"] = nFileID++;
dr ["FileName"] = file.Name;
dr ["Description"] = file.Name;
dt.Rows.Add( dr );
}
Icon.DataSource = dt;
Icon.DataValueField = "FileName";
Icon.DataTextField = "Description";
}
DataBind();
if ( Request ["s"] != null )
{
using ( DataTable dt = YAF.Classes.Data.DB.smiley_list( PageContext.PageBoardID, Request.QueryString ["s"] ) )
{
if ( dt.Rows.Count > 0 )
{
Code.Text = dt.Rows [0] ["Code"].ToString();
Emotion.Text = dt.Rows [0] ["Emoticon"].ToString();
if ( Icon.Items.FindByText( dt.Rows [0] ["Icon"].ToString() ) != null ) Icon.Items.FindByText( dt.Rows [0] ["Icon"].ToString() ).Selected = true;
Preview.Src = String.Format( "{0}images/emoticons/{1}", YafForumInfo.ForumRoot, dt.Rows [0] ["Icon"] );
SortOrder.Text = dt.Rows [0] ["SortOrder"].ToString(); // Ederon : 9/4/2007
}
}
}
else
{
Preview.Src = String.Format( "{0}images/spacer.gif", YafForumInfo.ForumRoot );
}
Icon.Attributes ["onchange"] = String.Format(
"getElementById('{1}').src='{0}images/emoticons/' + this.value",
YafForumInfo.ForumRoot,
Preview.ClientID
);
}
开发者ID:coredweller,项目名称:PhishMarket,代码行数:60,代码来源:smilies_edit.ascx.cs
示例19: button1_Click
private void button1_Click(object sender, EventArgs e)
{
string katalognavn = tbxKatalognavn.Text.Trim();
// Viser brugen af DirectoryInfo til at hente info for et katalog
System.IO.DirectoryInfo dir = new System.IO.DirectoryInfo(katalognavn); // objekt med information for det angive katalognavn
if (dir.Exists) // tjek om katalog findes
{
textBox2.Text = dir.CreationTime.ToString() + Environment.NewLine;
System.IO.DirectoryInfo[] subDirs = dir.GetDirectories(); // Hent underliggende kataloginformationer for det angive katalog
foreach (System.IO.DirectoryInfo dirInfo in subDirs)
{
textBox2.Text = textBox2.Text + "Name:<" + dirInfo.Name + "> Extension:<" + dirInfo.Extension +">" + Environment.NewLine;
}
dataGridView1.DataSource = subDirs; // vis elementerne i grid formatet for demo af alle properties
}
else
textBox2.Text = "Katalog findes ikke";
}
开发者ID:caddeo,项目名称:SocketEksamenForberedelse,代码行数:26,代码来源:FormDemo.cs
示例20: LoadCaptureFolder
public static List<System.IO.DirectoryInfo> LoadCaptureFolder(string Path)
{
if(!System.IO.Directory.Exists(Path)) return null;
System.IO.DirectoryInfo dir = new System.IO.DirectoryInfo(Path);
return new List<System.IO.DirectoryInfo>(dir.GetDirectories());
}
开发者ID:DefStevo,项目名称:defstevo-collection,代码行数:7,代码来源:CaptureManager.cs
注:本文中的System.IO.DirectoryInfo类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论