当前位置: 首页>>代码示例>>C#>>正文


C# IO.DirectoryInfo类代码示例

本文整理汇总了C#中System.IO.DirectoryInfo的典型用法代码示例。如果您正苦于以下问题:C# System.IO.DirectoryInfo类的具体用法?C# System.IO.DirectoryInfo怎么用?C# System.IO.DirectoryInfo使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


System.IO.DirectoryInfo类属于命名空间,在下文中一共展示了System.IO.DirectoryInfo类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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


注:本文中的System.IO.DirectoryInfo类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。