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


C# DirectoryInfo.ToString方法代码示例

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


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

示例1: CopyDirectoryTree

        public static bool CopyDirectoryTree(this DirectoryInfo source, DirectoryInfo dest)
        {
            bool wasModified = false;

            if (!Directory.Exists(dest.FullName))
                Directory.CreateDirectory(dest.FullName);

            foreach (FileInfo file in source.EnumerateFiles())
            {
                var fileDest = Path.Combine(dest.ToString(), file.Name);
                if (!File.Exists(fileDest))
                {
                    file.CopyTo(fileDest);
                    wasModified = true;
                }
            }

            foreach (DirectoryInfo subDirectory in source.GetDirectories())
            {
                var dirDest = Path.Combine(dest.ToString(), subDirectory.Name);
                DirectoryInfo newDirectory = dest.CreateSubdirectory(subDirectory.Name);
                if (CopyDirectoryTree(subDirectory, newDirectory))
                    wasModified = true;
            }

            return wasModified;
        }
开发者ID:niv,项目名称:ArmALauncher,代码行数:27,代码来源:Helpers.cs

示例2: Copy

        public static void Copy(string sourcePath, string targetPath)
        {
            var source = new DirectoryInfo(ToFullPath(sourcePath));
            var target = new DirectoryInfo(ToFullPath(targetPath));

            if (!source.Exists)
            {
                return;
            }
            if (!target.Exists)
            {
                target.Create();
            }

            // Copy each file into the new directory.
            foreach (FileInfo sourceFile in source.GetFiles())
            {
                var targetFilename = Path.Combine(target.ToString(), sourceFile.Name);
                sourceFile.CopyTo(targetFilename, true);
            }

            // Copy each subdirectory using recursion.
            foreach (DirectoryInfo sourceSubdirectory in source.GetDirectories())
            {
                var targetSubdirectory = Path.Combine(target.ToString(), sourceSubdirectory.Name);
                Copy(sourceSubdirectory.FullName, targetSubdirectory);
            }
        }
开发者ID:Codestellation,项目名称:Quarks,代码行数:28,代码来源:Folder.cs

示例3: TargetCompile

 public static void TargetCompile()
 {
     TargetClean();
     Directory.CreateDirectory(buildDir);
     DirectoryInfo thisDir = new DirectoryInfo(Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location));
     string currentPath = thisDir.ToString();
     DirectoryInfo[] srcArray = thisDir.GetDirectories("src");
     if(srcArray.Length == 1)
     {
         DirectoryInfo srcDir = srcArray[0];
         FileInfo[] sourceFiles = srcDir.GetFiles("*.cs", SearchOption.AllDirectories);
         foreach(FileInfo fi in sourceFiles)
         {
             addFile(fi, currentPath);
         }
         Process process = new Process();
         process.StartInfo.FileName = "mcs";
         process.StartInfo.Arguments = files.Trim() + " -out:" + outputFile;
         process.Start();
     }
     else
     {
         Console.WriteLine("There is a problem with the src directory.");
     }
 }
开发者ID:replacewythy,项目名称:builder,代码行数:25,代码来源:Builder.cs

示例4: InsertMsg

        public static void InsertMsg(string msg)
        {
            //锁住写日文对象,防止多线程同时写文件,造成并发。
            //Update by Chen De Jun 2013-10-8
            lock (_fileLockObj)
            {
                var dt = DateTime.Now;
                var di = new DirectoryInfo(Application.StartupPath + "\\" + DirectPath);
                if (di.Exists == false) di.Create();
                var disub = new DirectoryInfo(di.ToString() + "\\" + dt.ToString("yyyy-MM"));
                if (disub.Exists == false) disub.Create();

                //每天生成一个文件,会造成文件容易增加,减慢效率。故意每天每小时生成一个文件。 
                //Update by Chen De Jun 2013-10-8
                var filePath = disub.ToString() + "\\" + dt.ToString("yyyy-MM-dd HH") + ".txt";

                if (!File.Exists(filePath))
                {
                    FileStream fs = File.Create(filePath);//防止产生“另一个进程访问”出错,不能直接Create
                    fs.Flush();
                    fs.Close();
                }
                var filestream = new System.IO.FileStream(filePath, System.IO.FileMode.Append, System.IO.FileAccess.Write, FileShare.ReadWrite);
                var sw = new StreamWriter(filestream, Encoding.GetEncoding("gb2312"));
                //File.AppendText(FilePath);
                sw.WriteLine(msg);
                sw.Flush();
                sw.Close();
            }
        }
开发者ID:lzhaofu,项目名称:OSS,代码行数:30,代码来源:LogFileHelper.cs

示例5: CopyDirectoryAll

        // Taken from: http://xneuron.wordpress.com/2007/04/12/copy-directory-and-its-content-to-another-directory-in-c/
        public static void CopyDirectoryAll(DirectoryInfo source, DirectoryInfo target)
        {
            // Check if the target directory exists, if not, create it.
            if (Directory.Exists(target.FullName) == false)
            {
                Directory.CreateDirectory(target.FullName);
            }

            // Copy each file into it’s new directory.
            foreach (FileInfo fi in source.GetFiles())
            {
                Trace.WriteLine(String.Format(@"Copying {0}{1}", target.FullName, fi.Name));
                fi.CopyTo(Path.Combine(target.ToString(), fi.Name), true);
            }

            // Copy each subdirectory using recursion.
            foreach (DirectoryInfo diSourceSubDir in source.GetDirectories())
            {
                // Ignore .svn directories
                if (diSourceSubDir.Name == ".svn") continue;

                DirectoryInfo nextTargetSubDir =
                    target.CreateSubdirectory(diSourceSubDir.Name);
                CopyDirectoryAll(diSourceSubDir, nextTargetSubDir);
            }
        }
开发者ID:smtheard,项目名称:PokerMuck,代码行数:27,代码来源:VisualMatcher.cs

示例6: CopyAll

        /// <summary>
        /// Copy files in a direcory and its subdirectories to another directory.
        /// </summary>
        /// <param name="source"></param>
        /// <param name="target"></param>
        /// <param name="ignorePath"></param>
        public static void CopyAll(DirectoryInfo source, DirectoryInfo target, string ignorePath)
        {
            // Copy each subdirectory using recursion.
            foreach (DirectoryInfo diSourceSubDir in source.GetDirectories())
            {
                if (diSourceSubDir.Name == ignorePath)
                    continue;
                // Check if the target directory exists, if not, create it.
                if (Directory.Exists(target.FullName) == false)
                {
                    Directory.CreateDirectory(target.FullName);
                }

                DirectoryInfo nextTargetSubDir = target.CreateSubdirectory(diSourceSubDir.Name);

                CopyAll(diSourceSubDir, nextTargetSubDir, ignorePath);
            }

            // Copy each file into it's new directory.
            foreach (FileInfo fi in source.GetFiles())
            {
                Console.WriteLine(@"Copying {0}\{1}", target.FullName, fi.Name);
                String path = Path.Combine(target.ToString(), fi.Name);
                fi.CopyTo(path, true);
            }
        }
开发者ID:lishxi,项目名称:_SharpMap,代码行数:32,代码来源:FileUtils.cs

示例7: BuildTree

        public static Folder BuildTree(DirectoryInfo root)
        {
            string directoryName = root.ToString();
            List<File> directoryFiles = new List<File>();
            List<Folder> subdirs = new List<Folder>();

            try
            {
                var currentFiles = root.GetFiles();
                foreach (var file in currentFiles)
                {
                    directoryFiles.Add(new File(file.Name, (int)(file.Length)));
                }

                var currentSubdirectories = root.GetDirectories();
                foreach (var subdirectory in currentSubdirectories)
                {
                    subdirs.Add(BuildTree(subdirectory));
                }
            }
            catch (UnauthorizedAccessException)
            {
            }

            return new Folder(directoryName, directoryFiles.ToArray(), subdirs.ToArray());
        }
开发者ID:ilkodzhambazov,项目名称:Telerik-Academy,代码行数:26,代码来源:Program.cs

示例8: copyFiles

        public static void copyFiles(DirectoryInfo source, DirectoryInfo target)
        {
            if (source.FullName.Contains(".svn")) return;

            // Check if the target directory exists, if not, create it.
            if (Directory.Exists(target.FullName) == false)
            {
                Directory.CreateDirectory(target.FullName);
            }

            if (Directory.Exists(source.FullName) == true)
            {
                // Copy each file into it’s new directory.
                foreach (FileInfo file in source.GetFiles())
                {
                    if (file.Extension.Equals(".esp"))
                    {
                        continue;
                    }
                    bool isFileExist = true;
                    foreach (FileInfo extFile in target.GetFiles())
                    {
                        if (file.Name.Equals(extFile.Name))
                        {
                            isFileExist = false;
                        }
                    }
                    if (isFileExist)
                    {
                        file.CopyTo(Path.Combine(target.ToString(), file.Name), false);
                    }
                }
            }
        }
开发者ID:harpreetoxyent,项目名称:pnl,代码行数:34,代码来源:RenderUtil.cs

示例9: ExtractFilesInDirectory

        public bool ExtractFilesInDirectory(string directoryname)
        {
            if (Directory.Exists(directoryname) == false)
                return false;

            DirectoryInfo searchdir = new DirectoryInfo(directoryname);
            var zips = from zipfiles in searchdir.GetFiles()
                       where zipfiles.Extension == ".zip"
                       select zipfiles.FullName;

            foreach (string zip in zips)
            {
                Console.WriteLine(string.Concat("Unzipping ", zip.ToString(), "............."));
                string unpacks = zip.ToString();

                using (ZipFile z = ZipFile.Read(unpacks))
                {
                    foreach (ZipEntry e in z)
                    {
                        e.Extract(searchdir.ToString(), ExtractExistingFileAction.OverwriteSilently);
                        Console.WriteLine(e.FileName);
                    }
                }
                LastFileUnzipped = zip;
            }

            return true;
        }
开发者ID:ercrgg,项目名称:MongoBannerlinkExtraction,代码行数:28,代码来源:Extraction.cs

示例10: Load

        /// <summary>
        /// Loads the plugins, from the plugins directory
        /// </summary>
        /// <remarks>
        /// uses System.ComponentModel.Composition to do all the heavy lifting.
        /// </remarks>
        public static void Load(App obj)
        {
            var pluginsDirectoryInfo = new DirectoryInfo(Settings.Default.GetAppDataPath () + "plugins");
            if(!pluginsDirectoryInfo.Exists)
            {
                try
                {
                    pluginsDirectoryInfo.Create();
                }
                catch(Exception ex)
                {
                    Console.Write(ex.Message);
                }
            }

            var catalog = new AggregateCatalog();
            //catalog.Catalogs.Add(new AssemblyCatalog(typeof(App).Assembly));
            catalog.Catalogs.Add(new DirectoryCatalog(pluginsDirectoryInfo.ToString()));

            var container = new CompositionContainer(catalog);

            try
            {
                container.ComposeParts(obj);
            }
            catch(CompositionException ex)
            {
                Console.Write(ex.Message);
            }
        }
开发者ID:scottc,项目名称:xdcc-grabscher,代码行数:36,代码来源:Plugins.cs

示例11: CreateFolders

 static void CreateFolders(DirectoryInfo dir, int count)
 {
     for (int i = 1; i <= count; i++)
     {
         Directory.CreateDirectory(dir.ToString() + "\\generated" + i);
     }
 }
开发者ID:usedflax,项目名称:flaxbox,代码行数:7,代码来源:Program.cs

示例12: CreateFiles

 static void CreateFiles(DirectoryInfo dir, int count)
 {
     for (int i = 1; i <= count; i++)
     {
         File.Create(dir.ToString() + "\\generated" + i + ".gen");
     }
 }
开发者ID:usedflax,项目名称:flaxbox,代码行数:7,代码来源:Program.cs

示例13: OnPostProcessBuild

				// add the JSONPersistor.filePath to the build!
				public static void OnPostProcessBuild (BuildTarget target, string path)
				{
						//Debug.Log ("OnPostProcessBuild target " + target + " path " + path);

						// Get Required Paths
						//DirectoryInfo projectParent = Directory.GetParent (Application.dataPath);
						DirectoryInfo projectParent = new DirectoryInfo (Application.dataPath);
						string buildname = Path.GetFileNameWithoutExtension (path);
						DirectoryInfo targetdir = Directory.GetParent (path);
						char divider = Path.DirectorySeparatorChar;

						string dataMarker = "";
						#if UNITY_STANDALONE_WIN
						dataMarker = "_Data";
						#endif

						string buildDataDir = targetdir.FullName + divider + buildname + dataMarker + JSONPersistor.FilePathInUnity;
						string unitySourceFolder = projectParent.ToString () + JSONPersistor.FilePathInUnity;

						//Debug.Log ("copy all from " + unitySourceFolder + " to " + buildDataDir.ToString ());

						filecount = 0;
						dircount = 0;

						CopyAll (new DirectoryInfo (unitySourceFolder), new DirectoryInfo (buildDataDir));

						//Debug.Log ("Copied: " + filecount + " file" + ((filecount != 1) ? "s" : "") + ", " + dircount + " folder" + ((dircount != 1) ? "s" : ""));
				}
开发者ID:DomDomHaas,项目名称:JSONPersistency,代码行数:29,代码来源:PostBuildHook.cs

示例14: CopyDirectoryRecursively

		/// <summary>
		/// Copy all directory contents including sub-folders recursively, applying filtering pattern
		/// </summary>
		/// <param name="sourceDirectory">the source directory contents to be copied</param>
		/// <param name="targetDirectory">where to copy the files and folders</param>
		/// <param name="extensions">extensions to be used to filter files to be copied, e.g. .pdb;.exe;.dll. Set to null to include all.</param>
		public static void CopyDirectoryRecursively(string sourceFolder, string targetFolder, string extensions)
		{
			DirectoryInfo sourceFolderInfo = new DirectoryInfo(sourceFolder);
			DirectoryInfo targetFolderInfo = new DirectoryInfo(targetFolder);
			string[] extensionsArray = (extensions != null) ? extensions.Split(';') : null;

			// Check if the target directory exists, if not, create it.
			if (Directory.Exists(targetFolderInfo.FullName) == false)
			{
				Directory.CreateDirectory(targetFolderInfo.FullName);
			}

			// Copy each file into it’s new directory.
			foreach (FileInfo sourceFileInfo in sourceFolderInfo.GetFiles("*"))
			{
				string fileExtension = sourceFileInfo.Extension;
				bool match = (extensions == null);
				if (!match)
				{
					foreach (string extension in extensionsArray) { if (fileExtension == extension) { match = true; break; } }
				}
				if (match)
				{
					sourceFileInfo.CopyTo(Path.Combine(targetFolderInfo.ToString(), sourceFileInfo.Name), true);
				}
			}

			// Copy each subdirectory using recursion.
			foreach (DirectoryInfo sourceSubFolderInfo in sourceFolderInfo.GetDirectories())
			{
				DirectoryInfo nextTargetSubFolder = targetFolderInfo.CreateSubdirectory(sourceSubFolderInfo.Name);
				DirectoryTools.CopyDirectoryRecursively(sourceSubFolderInfo.FullName, nextTargetSubFolder.FullName, extensions);
			}
		}
开发者ID:ntung,项目名称:ToolsPack.Net,代码行数:40,代码来源:DirectoryTools.cs

示例15: SaveUploadedFile

        public ActionResult SaveUploadedFile(EtkinlikModel etkinlik)
        {
            bool isSavedSuccessfully = true;
            string fName = "";
            var path = "";
            try
            {
                foreach (string fileName in Request.Files)
                {
                    HttpPostedFileBase file = Request.Files[fileName];
                    //Save file content goes here
                    fName = file.FileName;
                    if (file != null && file.ContentLength > 0)
                    {

                        var originalDirectory = new DirectoryInfo(string.Format("{0}Images\\Afis", Server.MapPath(@"\")));

                        string pathString = System.IO.Path.Combine(originalDirectory.ToString(), "imagepath");

                        var fileName1 = Path.GetFileName(file.FileName);

                        bool isExists = System.IO.Directory.Exists(pathString);

                        if (!isExists)
                            System.IO.Directory.CreateDirectory(pathString);

                        path = string.Format("{0}\\{1}", pathString, file.FileName);
                        file.SaveAs(path);

                    }

                }

            }
            catch (Exception ex)
            {
                isSavedSuccessfully = false;
            }


            if (isSavedSuccessfully)
            {
                RestService service = new RestService();
                RestRequest request = new RestRequest("api/Etkinliks", Method.POST);
                var token = Request.Headers["Authorization"];
                request.AddParameter("Adi", etkinlik.EtkinlikAdi);
                request.AddParameter("Tarihi", etkinlik.EtkinlikTarihi.ToShortDateString());
                request.AddParameter("AcilisTarihi", etkinlik.AcilisTarihi);
                request.AddParameter("KapanisTarihi", etkinlik.KapanisTarihi);
                request.AddParameter("Aciklama", etkinlik.Aciklama);
                request.AddParameter("FotoName", fName);

                var result = service.Execute<Object>(request,token);
                return Json(result, JsonRequestBehavior.AllowGet);
            }
            else
            {
                return Json(new { Message = "Error in saving file" });
            }
        }
开发者ID:mistikk,项目名称:sauemk,代码行数:60,代码来源:AdminController.cs


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