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


C# IO.DirectoryInfo类代码示例

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


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

示例1: ManagedProjectReference

        public ManagedProjectReference(XmlElement xmlDefinition, ReferencesResolver referencesResolver, ProjectBase parent, SolutionBase solution, TempFileCollection tfc, GacCache gacCache, DirectoryInfo outputDir)
            : base(referencesResolver, parent)
        {
            if (xmlDefinition == null) {
                throw new ArgumentNullException("xmlDefinition");
            }
            if (solution == null) {
                throw new ArgumentNullException("solution");
            }
            if (tfc == null) {
                throw new ArgumentNullException("tfc");
            }
            if (gacCache == null) {
                throw new ArgumentNullException("gacCache");
            }

            XmlAttribute privateAttribute = xmlDefinition.Attributes["Private"];
            if (privateAttribute != null) {
                _isPrivateSpecified = true;
                _isPrivate = bool.Parse(privateAttribute.Value);
            }

            // determine path of project file
            string projectFile = solution.GetProjectFileFromGuid(
                xmlDefinition.GetAttribute("Project"));

            // load referenced project
            _project = LoadProject(solution, tfc, gacCache, outputDir, projectFile);
        }
开发者ID:smaclell,项目名称:NAnt,代码行数:29,代码来源:ManagedProjectReference.cs

示例2: BattleDetailLogger

 public BattleDetailLogger()
 {
     Directory.CreateDirectory(@"logs\battlelog");
     Staff.API("api_req_map/start").Subscribe(x => AddApi("startnext", x));
     Staff.API("api_req_map/next").Subscribe(x => AddApi("startnext", x));
     Staff.API("api_req_sortie/battleresult").Subscribe(x => AddApi("battleresult", x));
     Staff.API("api_req_combined_battle/battleresult").Subscribe(x => AddApi("battleresult", x));
     Staff.API("api_req_sortie/battle").Subscribe(x => AddApi("battle", x));
     Staff.API("api_req_battle_midnight/battle").Subscribe(x => AddApi("nightbattle", x));
     Staff.API("api_req_battle_midnight/sp_midnight").Subscribe(x => AddApi("battle", x));
     //Staff.API("api_req_practice/battle").Subscribe(x => AddApi("battle", x));
     //Staff.API("api_req_practice/midnight_battle").Subscribe(x => AddApi("nightbattle", x));
     Staff.API("api_req_sortie/airbattle").Subscribe(x => AddApi("battle", x));
     Staff.API("api_req_sortie/ld_airbattle").Subscribe(x => AddApi("battle", x));
     Staff.API("api_req_combined_battle/airbattle").Subscribe(x => AddApi("battle", x));
     Staff.API("api_req_combined_battle/battle").Subscribe(x => AddApi("battle", x));
     Staff.API("api_req_combined_battle/midnight_battle").Subscribe(x => AddApi("nightbattle", x));
     Staff.API("api_req_combined_battle/sp_midnight").Subscribe(x => AddApi("battle", x));
     Staff.API("api_req_combined_battle/battle_water").Subscribe(x => AddApi("battle", x));
     Staff.API("api_req_combined_battle/ld_airbattle").Subscribe(x => AddApi("battle", x));
     Staff.API("api_req_combined_battle/ec_battle").Subscribe(x => AddApi("battle", x));
     Staff.API("api_req_combined_battle/ec_midnight_battle").Subscribe(x => AddApi("battle", x));
     Staff.API("api_req_combined_battle/each_battle").Subscribe(x => AddApi("battle", x));
     Staff.API("api_req_combined_battle/each_battle_water").Subscribe(x => AddApi("battle", x));
     var dir = new DirectoryInfo(@"logs\battlelog");
     foreach (var file in dir.GetFiles("*.log"))
     {
         date = DateTime.Parse(Path.GetFileNameWithoutExtension(file.Name));
         if (date != DateTime.UtcNow.Date)
             CompressFile();
     }
     date = DateTime.UtcNow.Date;
 }
开发者ID:huoyaoyuan,项目名称:AdmiralRoom,代码行数:33,代码来源:BattleDetailLogger.cs

示例3: LoadPlugins

		public void LoadPlugins(string pluginPath, bool checkSubDirs)
		{
			if(!Directory.Exists(pluginPath))
				return;
			if(Plugins.Any())
				UnloadPlugins();
			var dirInfo = new DirectoryInfo(pluginPath);

			var files = dirInfo.GetFiles().Select(f => f.FullName).ToList();
			if(checkSubDirs)
			{
				foreach(var dir in dirInfo.GetDirectories())
					files.AddRange(dir.GetFiles().Select(f => f.FullName));
			}

			foreach(var file in files)
			{
				var fileInfo = new FileInfo(file);

				if(fileInfo.Extension.Equals(".dll"))
				{
					var plugins = GetModule(file, typeof(IPlugin));
					foreach(var p in plugins)
						Plugins.Add(p);
				}
			}
			Logger.WriteLine("Loading Plugins...", "PluginManager");
			LoadPluginSettings();
		}
开发者ID:rudzu,项目名称:Hearthstone-Deck-Tracker,代码行数:29,代码来源:PluginManager.cs

示例4: BtDeleteClick

        /// <summary>
        /// Remove directories and files if selected
        /// </summary>
        private void BtDeleteClick(object sender, EventArgs e)
        {
            // Move CWD away as it prevents Windows OS to cleanly delete directory
            Directory.SetCurrentDirectory(App.AppHome);

            bool ret = true;
            // Depending on the selection, do the deletion:
            // 0: dont delete anythng
            // 1: delete only working files
            // 2: delete only .git tree
            // 3: delete complete repo folder

            if (_radioSelection == 1)
            {
                DirectoryInfo dirInfo = new DirectoryInfo(_dir);
                ret = ClassUtils.DeleteFolder(dirInfo, true, true);     // Preserve .git, preserve root folder
            }

            if (_radioSelection == 2)
            {
                DirectoryInfo dirInfo = new DirectoryInfo(_dir + Path.DirectorySeparatorChar + ".git");
                ret = ClassUtils.DeleteFolder(dirInfo, false, false);    // Remove .git, remove root folder (.git)
            }

            if(_radioSelection == 3)
            {
                DirectoryInfo dirInfo = new DirectoryInfo(_dir);
                ret = ClassUtils.DeleteFolder(dirInfo, false, false);   // Remove .git, remove root folder
            }

            if (ret == false)
                MessageBox.Show("Some files could not be removed!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
        }
开发者ID:splintor,项目名称:GitForce,代码行数:36,代码来源:FormDeleteRepo.cs

示例5: GetLatestUpdate

        public DateTime? GetLatestUpdate()
        {
            if (_lastUpdated.HasValue) return _lastUpdated;

            var directory = new DirectoryInfo(BaseDirectory);

            var latest =
                directory.GetFiles("*.*", SearchOption.AllDirectories)
                    .OrderByDescending(f => f.LastWriteTimeUtc)
                    .FirstOrDefault();

            _lastUpdated = latest != null ? (DateTime?)latest.LastWriteTimeUtc : null;
            return _lastUpdated;
            /*
            var directory = new DirectoryInfo(BaseDirectory);

            if (!directory.Exists)
            {
                directory.Create();
                return null;
            }

            var latest =
    directory.GetFiles("*.*", SearchOption.AllDirectories)
        .OrderByDescending(f => f.LastWriteTimeUtc)
        .FirstOrDefault();

            return latest != null ? (DateTime?)latest.LastWriteTimeUtc : null;
             * */
        }
开发者ID:rajendra1809,项目名称:VirtoCommerce,代码行数:30,代码来源:FileStorageCacheService.cs

示例6: GetBabylonScenes

        public string GetBabylonScenes(string rootPath)
        {
            try
            {
                var dir = new DirectoryInfo(rootPath);
                var subDirs = dir.GetDirectories();
                var files = new List<JObject>();

                foreach (var directory in subDirs)
                {
                    var babylonFiles = directory.GetFiles("*.babylon");

                    if (babylonFiles.Length == 0)
                        continue;

                    foreach (var file in babylonFiles)
                    {
                        var linkName = directory.Name + "/" + Path.GetFileNameWithoutExtension(file.Name);
                        files.Add(new JObject(
                            new JProperty("url", Url.Action("Index", "BabylonJSDemo", new { demoFolderName = directory.Name, demoFile = file.Name })),
                            new JProperty("linkName", linkName)
                        ));
                    }
                }

                var json = new JObject(new JProperty("files", files));
                return json.ToString(Newtonsoft.Json.Formatting.None);
            }
            catch
            {
                var json = new JObject(new JProperty("files", ""));
                return json.ToString(Newtonsoft.Json.Formatting.None);
            }
        }
开发者ID:Zaxou,项目名称:Babylon.js,代码行数:34,代码来源:BuildOurOwnBabylonJSController.cs

示例7: LoadTemplateData

        public void LoadTemplateData()
        {
            #region 加载模板数据

            path = Utils.GetMapPath(@"..\..\templates\");

            string templatepath = "由于目录 : ";
            string templateidlist = "0";
            foreach (DataRow dr in buildGridData().Select("valid =1"))
            {
                DirectoryInfo dirinfo = new DirectoryInfo(path + dr["directory"].ToString() + "/");
                if (dr["directory"].ToString().ToLower() == "default")
                    continue;
                if (!dirinfo.Exists)
                {
                    templatepath += dr["directory"].ToString() + " ,";
                    templateidlist += "," + dr["templateid"].ToString();
                }
            }

            if ((templateidlist != "") && (templateidlist != "0"))
            {
                base.RegisterStartupScript("", "<script>alert('" + templatepath.Substring(0, templatepath.Length - 1) + "已被删除, 因此系统将自动更新模板列表!')</script>");
                AdminTemplates.DeleteTemplateItem(templateidlist);
                AdminVistLogs.InsertLog(this.userid, this.username, this.usergroupid, this.grouptitle, this.ip, "从数据库中删除模板文件", "ID为:" + templateidlist);
                Discuz.Cache.DNTCache.GetCacheService().RemoveObject("/Forum/TemplateIDList");
                Discuz.Forum.Templates.GetValidTemplateIDList();
            }

            DataGrid1.AllowCustomPaging = false;
            DataGrid1.DataSource = buildGridData();
            DataGrid1.DataBind();

            #endregion
        }
开发者ID:khaliyo,项目名称:DiscuzNT,代码行数:35,代码来源:global_templatesgrid.aspx.cs

示例8: ExtractZipArchive

        private static bool ExtractZipArchive(string archive, string destination, FastZip fz)
        {

            DirectoryInfo newdirFI;

            if (!Directory.Exists(destination))
            {
                newdirFI = Directory.CreateDirectory(destination);

                if (!Directory.Exists(newdirFI.FullName))
                {
                    //MessageBox.Show("Directory " + destination + " could not be created.");
                    return false;
                }
            }
            else newdirFI = new DirectoryInfo(destination);


            try
            {
                Thread.Sleep(500);
                fz.ExtractZip(archive, newdirFI.FullName, "");
            }
            catch (Exception e)
            {
                Debugger.LogMessageToFile("The archive " + archive + " could not be extracted to destination " + destination +
                                          ". The following error ocurred: " + e);
            }



            return true;
        }
开发者ID:stavrossk,项目名称:MeediFier_for_MeediOS,代码行数:33,代码来源:ArchiveExtractor.cs

示例9: CreateDirectoryIfNotExists

 private static void CreateDirectoryIfNotExists(DirectoryInfo directoryInfo)
 {
     if(!directoryInfo.Exists) {
         CreateDirectoryIfNotExists(directoryInfo.Parent);
         directoryInfo.Create();
     }
 }
开发者ID:penartur,项目名称:FLocal,代码行数:7,代码来源:UploadHandler.cs

示例10: AddDirectoryAsync

        private IEnumerable<XElement> AddDirectoryAsync(DirectoryInfo dir, string collectionId, ref int count, int fnumber,
            BackgroundWorker worker)
        {
            List<XElement> addedElements = new List<XElement>();
            // добавление коллекции
            string subCollectionId;
            List<XElement> ae = this.cass.AddCollection(dir.Name, collectionId, out subCollectionId).ToList();
            if (ae.Count > 0) addedElements.AddRange(ae);

            count++;
            foreach (FileInfo f in dir.GetFiles())
            {
                if (worker.CancellationPending) break;
                if (f.Name != "Thumbs.db")
                    addedElements.AddRange(this.cass.AddFile(f, subCollectionId));
                count++;
                worker.ReportProgress(100 * count / fnumber);
            }
            foreach (DirectoryInfo d in dir.GetDirectories())
            {
                if (worker.CancellationPending) break;
                addedElements.AddRange(AddDirectoryAsync(d, subCollectionId, ref count, fnumber, worker));
            }
            return addedElements;
        }
开发者ID:agmarchuk,项目名称:CManager,代码行数:25,代码来源:CM_WindowDND.cs

示例11: NewlyCreatedFileDirectory

        public static void NewlyCreatedFileDirectory()
        {
            DirectoryInfo directory = new DirectoryInfo("C:\\");
            FileInfo file = directory.GetFiles().OrderByDescending(f => f.LastWriteTime).First();
            Console.WriteLine("\n\nName:" + file.Name);
            Console.WriteLine("Full Name:" + file.FullName);
            Console.WriteLine("Read-Only:" + file.IsReadOnly);
            Console.WriteLine("Last Acces Time:" + file.LastAccessTime);
            Console.WriteLine("Last Write Time:" + file.LastWriteTime);
            Console.WriteLine("Length:" + file.Length);
            Console.WriteLine("Extension:" + file.Extension);
            Console.WriteLine("Attributes:" + file.Attributes);
            Console.WriteLine("Creation Time:" + file.CreationTime);
            Console.WriteLine("Directory Name: " + file.DirectoryName);

            DirectoryInfo directory1 = directory.GetDirectories().OrderByDescending(f => f.LastWriteTime).First();
            Console.WriteLine("\n\nDirectory Name:" + directory1.Name);
            Console.WriteLine("Parent:" + directory1.Parent);
            Console.WriteLine("Root:" + directory1.Root);
            Console.WriteLine("Last Write Time:" + directory1.LastWriteTime);
            Console.WriteLine("Last Access Time:" + directory1.LastAccessTime);
            Console.WriteLine("Extension:" + directory1.Extension);
            Console.WriteLine("Creation Time:" + directory1.CreationTime);
            Console.WriteLine("Attributes" + directory1.Attributes);
        }
开发者ID:jaskarans-optimus,项目名称:Induction,代码行数:25,代码来源:Program.cs

示例12: btnUpload_Click

        protected void btnUpload_Click(object sender, EventArgs e)
        {
            lb_notvalid.Visible = false;

            if (FileUpload1.HasFile)
            {
                Guid g = Guid.NewGuid();
                DirectoryInfo updir = new DirectoryInfo(Server.MapPath("/media/upload/" + g));

                if (!updir.Exists)
                    updir.Create();

                FileUpload1.SaveAs(updir.FullName + "/" + FileUpload1.FileName);

                if (IsValidImage(updir.FullName + "/" + FileUpload1.FileName))
                {

                    tb_url.Text = "/media/upload/" + g + "/" +
                        ResizeImage(updir.FullName + "/", FileUpload1.FileName,
                        500, 1000, true);
                }
                else
                {
                    lb_notvalid.Visible = true;
                }
            }
        }
开发者ID:Jeavon,项目名称:OurUmbraco,代码行数:27,代码来源:InsertImage.ascx.cs

示例13: WalkDirectoryTree

        private void WalkDirectoryTree(DirectoryInfo rootDir)
        {
            FileInfo[] files = null;
            DirectoryInfo[] dirInfo = null;
            try
            {
                files = rootDir.GetFiles("*.*");

            }
            catch (Exception e)
            {
                log.Add(e.Message);
            }

            if (files != null)
            {
                foreach (FileInfo fi in files)
                {
                    Console.WriteLine(fi.FullName);

                }

                dirInfo = rootDir.GetDirectories();
                foreach (var dir in dirInfo)
                {
                    WalkDirectoryTree(dir);
                }
            }
        }
开发者ID:jscanlon77,项目名称:Interview,代码行数:29,代码来源:RecursionExample.cs

示例14: Run

        protected override int Run(BuildEngine engine)
        {
			foreach (ProjectInfo item in engine.Projects)
			{
				if (!String.IsNullOrEmpty(item.Properties[MSProp.SolutionDir]))
					continue;

				//To attempt to gracefully handle those those that use SolutionDir in build rules...
				string solutiondir = Path.GetDirectoryName(item.ProjectFile);
				DirectoryInfo parent = new DirectoryInfo(solutiondir);
				while (parent != null)
				{
					if (parent.GetFiles("*.sln").Length > 0)
					{
						solutiondir = parent.FullName;
						break;
					}
					parent = parent.Parent;
				}

				if (!solutiondir.EndsWith(@"\"))
					solutiondir += @"\";
				item.Properties[MSProp.SolutionDir] = solutiondir;
			}
            return 0;
        }
开发者ID:hivie7510,项目名称:csharptest-net,代码行数:26,代码来源:SetSolutionDir.cs

示例15: ClearLogFiles

        /// <summary>
        /// Clear all the log files older than 30 Days
        /// </summary>
        /// <param name="daysToKeep">
        /// The Number of Days to Keep
        /// </param>
        public static void ClearLogFiles(int daysToKeep)
        {
            if (Directory.Exists(LogDir))
            {
                // Get all the log files
                var info = new DirectoryInfo(LogDir);
                FileInfo[] logFiles = info.GetFiles("*.txt");

                // Delete old and excessivly large files (> ~50MB).
                foreach (FileInfo file in logFiles)
                {
                    try
                    {
                        if (file.LastWriteTime < DateTime.Now.AddDays(-daysToKeep))
                        {
                            File.Delete(file.FullName);
                        }
                        else if (file.Length > 50000000)
                        {
                            File.Delete(file.FullName);
                        }
                    }
                    catch (Exception)
                    {
                        // Silently ignore files we can't delete. They are probably being used by the app right now.
                    }
                }
            }
        }
开发者ID:JuannyWang,项目名称:HandBrake-QuickSync-Mac,代码行数:35,代码来源:GeneralUtilities.cs


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