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


C# FileInfo.Substring方法代码示例

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


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

示例1: Main

    static void Main(string[] args)
    {
        var outputDirPath = System.IO.Path.Combine(Application.StartupPath, "Output");
        if (!Directory.Exists(outputDirPath))
        {
            try
            {
                Directory.CreateDirectory(outputDirPath);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                Console.ReadKey();
                return;
            }
        }

        foreach (var fn in Directory.GetFiles(Application.StartupPath, "Template_*.dll"))
        {
            var asm = Assembly.LoadFile(fn);
            var t = TemplateScaner.GetTemplate(asm);
            var shortfn = new FileInfo(fn).Name;
            shortfn = shortfn.Substring(0, shortfn.LastIndexOf('.'));
            t.Name = shortfn.Substring("Template_".Length);
            var path = System.IO.Path.Combine(outputDirPath, shortfn.Replace(".", "_"));
            if (!Directory.Exists(path))
            {
                try
                {
                    Directory.CreateDirectory(path);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                    Console.ReadKey();
                    return;
                }
            }
            LoadSaves.LoadSaveAll(t, outputDirPath);

            GenCPP.Gen(t, path);
            // more gen here
        }

        Process.Start("explorer.exe", outputDirPath);
    }
开发者ID:denghe,项目名称:xxpkggen,代码行数:46,代码来源:Program.cs

示例2: DumpFiles

 public static void DumpFiles(string projectFilename, string baseDirectory)
 {
     List<string> files = new List<string>();
     files.Add(projectFilename);
     var stream = new MemoryStream(File.ReadAllBytes(projectFilename)); // cache file in memoty
     var document = XDocument.Load(stream);
     var xmlNamespaceManager = new XmlNamespaceManager(new NameTable());
     xmlNamespaceManager.AddNamespace("ns", namespaceName);
     IEnumerable<XElement> listOfSourceFiles = document.XPathSelectElements("/ns:Project/ns:ItemGroup/ns:Compile[@Include]", xmlNamespaceManager);
     foreach (var el in listOfSourceFiles)
     {
         files.Add(el.Attribute("Include").Value);
     }
     IEnumerable<XElement> listOfContentFiles = document.XPathSelectElements("/ns:Project/ns:ItemGroup/ns:Content[@Include]", xmlNamespaceManager);
     foreach (var el in listOfContentFiles)
     {
         files.Add(el.Attribute("Include").Value);
     }
     IEnumerable<XElement> listOfResourceFiles = document.XPathSelectElements("/ns:Project/ns:ItemGroup/ns:EmbeddedResource[@Include]", xmlNamespaceManager);
     foreach (var el in listOfResourceFiles)
     {
         files.Add(el.Attribute("Include").Value);
     }
     string separator = new string(Path.DirectorySeparatorChar, 1);
     string projDir = (new FileInfo(projectFilename)).Directory.FullName;
     foreach (string relativeName in files)
     {
         var correctedRelativeName = relativeName.Replace("\\", separator);
         string fullFileName = Path.Combine(projDir, correctedRelativeName);
         fullFileName = new FileInfo(fullFileName).FullName;
         string shortName;
         if (fullFileName.StartsWith(baseDirectory, StringComparison.InvariantCulture))
         {
             shortName = fullFileName.Substring(baseDirectory.Length);
             if (shortName.StartsWith(separator, StringComparison.InvariantCulture))
             {
                 shortName = shortName.Substring(1);
             }
         }
         else
         {
             shortName = fullFileName;
         }
         Console.WriteLine(shortName);
     }
 }
开发者ID:ArsenShnurkov,项目名称:mono-packaging-tools,代码行数:46,代码来源:ProjectTools.cs

示例3: Post

    public HttpResponseMessage Post(string action, string dirPath = "")
    {
        WebUtils.CheckRightsForAdminPostPages(false);

        HttpPostedFile file = HttpContext.Current.Request.Files[0];
        action = action.ToLowerInvariant();

        if (file != null && file.ContentLength > 0)
        {
            var dirName = string.Format("/{0}/{1}", DateTime.Now.ToString("yyyy"), DateTime.Now.ToString("MM"));
            var fileName = new FileInfo(file.FileName).Name; // to work in IE and others

            // iOS sends all images as "image.jpg" or "image.png"
            fileName = fileName.Replace("image.jpg", DateTime.Now.ToString("yyyyMMddHHmmssfff") + ".jpg");
            fileName = fileName.Replace("image.png", DateTime.Now.ToString("yyyyMMddHHmmssfff") + ".png");

            if (!string.IsNullOrEmpty(dirPath))
                dirName = dirPath;

            if (action == "filemgr" || action == "file")
            {
                string[] ImageExtensnios = { ".jpg", ".png", ".jpeg", ".tiff", ".gif", ".bmp" };

                if (ImageExtensnios.Any(x => fileName.ToLower().Contains(x.ToLower())))
                    action = "image";
                else
                    action = "file";
            }

            var dir = BlogService.GetDirectory(dirName);
            var retUrl = "";

            if (action == "import")
            {
                if (Security.IsAdministrator)
                {
                    return ImportBlogML();
                }
            }
            if (action == "profile")
            {
                if (Security.IsAuthorizedTo(Rights.EditOwnUser))
                {
                    // upload profile image
                    dir = BlogService.GetDirectory("/avatars");
                    var dot = fileName.LastIndexOf(".");
                    var ext = dot > 0 ? fileName.Substring(dot) : "";
                    var profileFileName = User.Identity.Name + ext;

                    var imgPath = HttpContext.Current.Server.MapPath(dir.FullPath + "/" + profileFileName);
                    var image = Image.FromStream(file.InputStream);
                    Image thumb = image.GetThumbnailImage(80, 80, () => false, IntPtr.Zero);
                    thumb.Save(imgPath);

                    return Request.CreateResponse(HttpStatusCode.Created, profileFileName);
                }
            }
            if (action == "image")
            {
                if (Security.IsAuthorizedTo(Rights.EditOwnPosts))
                {
                    var uploaded = BlogService.UploadFile(file.InputStream, fileName, dir, true);
                    return Request.CreateResponse(HttpStatusCode.Created, uploaded.AsImage.ImageUrl);
                }
            }
            if (action == "file")
            {
                if (Security.IsAuthorizedTo(Rights.EditOwnPosts))
                {
                    var uploaded = BlogService.UploadFile(file.InputStream, fileName, dir, true);
                    retUrl = uploaded.FileDownloadPath + "|" + fileName + " (" + BytesToString(uploaded.FileSize) + ")";
                    return Request.CreateResponse(HttpStatusCode.Created, retUrl);
                }
            }
            if (action == "video")
            {
                if (Security.IsAuthorizedTo(Rights.EditOwnPosts))
                {
                    // default media folder
                    var mediaFolder = "Custom/Media";

                    // get the mediaplayer extension and use it's folder
                    var mediaPlayerExtension = BlogEngine.Core.Web.Extensions.ExtensionManager.GetExtension("MediaElementPlayer");
                    mediaFolder = mediaPlayerExtension.Settings[0].GetSingleValue("folder");

                    var folder = Utils.ApplicationRelativeWebRoot + mediaFolder + "/";
                    //var fileName = file.FileName;

                    UploadVideo(folder, file, fileName);

                    return Request.CreateResponse(HttpStatusCode.Created, fileName);
                }
            }
        }
        return Request.CreateResponse(HttpStatusCode.BadRequest);
    }
开发者ID:doct15,项目名称:blogengine,代码行数:96,代码来源:UploadController.cs

示例4: ReorganizeSamples

	static void ReorganizeSamples(string workingDirectory)
	{
		string resourcesFolder = "."; // Project root
		string sourceResourcesDir = Path.Combine(workingDirectory, "Samples/UIResources");
		if (Directory.Exists(sourceResourcesDir))
		{
			resourcesFolder = resourcesFolder + "/UIResources";
			DirectoryInfo srcResDir = new DirectoryInfo(sourceResourcesDir);
			MoveAll(srcResDir, new DirectoryInfo(resourcesFolder), false);
			Directory.Delete(srcResDir.FullName, true);
			PlayerPrefs.SetString("CoherentUIResources", resourcesFolder);

			// Rename the .jstxt files back to .js
			string[] foldersWithJstxts = new string[] { resourcesFolder, Path.Combine(workingDirectory, "Samples") };
			DirectoryInfo assetsDirInfo = new DirectoryInfo(Application.dataPath);
			foreach (string folderWithJstxts in foldersWithJstxts)
			{
				if (!Directory.Exists(folderWithJstxts))
				{
					continue;
				}

				string[] jsFiles = Directory.GetFiles(folderWithJstxts, "*.jstxt", SearchOption.AllDirectories);
				foreach (string js in jsFiles)
				{
					string sourceName = new FileInfo(js).FullName;
					string targetName = sourceName.Substring(0, sourceName.Length - 3);
					if (!targetName.StartsWith(assetsDirInfo.FullName))
					{
						// Move as file
						if (File.Exists(targetName))
						{
							File.Delete(targetName);
						}
						File.Move(js, targetName);
					}
					else
					{
						// Move as asset
						string sourceAsset = "Assets" + sourceName.Substring(assetsDirInfo.FullName.Length).Replace('\\', '/');
						string targetAsset = "Assets" + targetName.Substring(assetsDirInfo.FullName.Length).Replace('\\', '/');
						if (File.Exists(targetName))
						{
							AssetDatabase.DeleteAsset(targetAsset);
						}
						string moveError = AssetDatabase.MoveAsset(sourceAsset, targetAsset);
						if (!string.IsNullOrEmpty(moveError))
						{
							Debug.LogError(moveError);
						}
					}
				}
			}

			string[] foldersWithCoherentJscripts = new string[] { Path.Combine(workingDirectory, "Samples/Scenes") };
			foreach (string folderWithJs in foldersWithCoherentJscripts)
			{
				if (!Directory.Exists(folderWithJs))
				{
					continue;
				}

				Regex regx = new Regex(@"#if.*#else(.*)#endif", RegexOptions.Singleline);
				string[] jsFiles = Directory.GetFiles(folderWithJs, "*.js", SearchOption.AllDirectories);
				foreach (string js in jsFiles)
				{
					string contents = File.ReadAllText(js);
					Match m = regx.Match(contents);
					if (m.Success)
					{
						File.WriteAllText(js, m.Groups[1].Value);
					}
				}
			}
		}
	}
开发者ID:Charkova,项目名称:MetaEden.a14,代码行数:76,代码来源:CoherentUIInstaller.cs

示例5: CreateHtmlReport


//.........这里部分代码省略.........
                                            <td width='10%' style='font-weight: " + Utility.GetParameter("ReportFontWeight") + @"; font-size: " + Utility.GetParameter("ReportFontSize") + @"; font-style:" + Utility.GetParameter("ReportFontStyle") + @"; color: " + Utility.GetParameter("ReportFontColor") + @"'>&nbsp;</td>
                                            <td width='15%' style='font-weight: " + Utility.GetParameter("ReportFontWeight") + @"; font-size: " + Utility.GetParameter("ReportFontSize") + @"; font-style:" + Utility.GetParameter("ReportFontStyle") + @"; color: " + Utility.GetParameter("ReportFontColor") + @"'>$TC_ExecutionTime_Date</td>
                                            <td width='25%' style='font-weight: " + Utility.GetParameter("ReportRemarksFontWeight") + @"; font-size: " + Utility.GetParameter("ReportFontSize") + @"; font-style:" + Utility.GetParameter("ReportRemarksFontStyle") + @"; color: " + Utility.GetParameter("ReportRemarksFontColor") + @"'>$TC_Remarks</td>
                                        </tr>
                                     </table>";
                string newTestCaseBodyEnd = @"</div>";

                string htmlEnd = @"</td>
                                 </tr>
                                  </table>
                                            </body>
                                </html>";

                //

                // Html Start
                finalHtml.Append(htmlStart);

                int count = 0;

                foreach (string xmlLocation in xmlFilesLocation)
                {
                    //using (StreamWriter sw = new StreamWriter(Property.ErrorLog))
                    //{
                    //    sw.WriteLine("Logfile Foreach 1");
                    //}
                    if (File.Exists(xmlLocation))
                    {
                        string rootFolderName = new FileInfo(xmlLocation).Directory.Parent.Name;
                        string rootFolderExt = string.Empty;
                        try
                        {
                            if (rootFolderName.Contains('-'))
                            rootFolderExt = rootFolderName.Substring(rootFolderName.IndexOf('-'),
                                                                            rootFolderName.Length -
                                                                            rootFolderName.IndexOf('-'));
                        }
                        catch
                        {
                            // ignored
                        }
                        Property.TotalCaseExecuted++;

                        try
                        {
                            #region Individual TestCase

                            var dsStore = new DataSet();
                            // copying all data from XML to datatable
                            dsStore.ReadXml(xmlLocation);

                            var dtTemp = dsStore.Tables[0];

                            // getting TestCase Name and ID from extended properties
                            if (dtTemp.ExtendedProperties["TestCase Name"] != null)
                                tcName = dtTemp.ExtendedProperties["TestCase Name"].ToString();
                            if (dtTemp.ExtendedProperties["TestCase Id"] != null)
                                tcId = dtTemp.ExtendedProperties["TestCase Id"].ToString();
                            if (dtTemp.ExtendedProperties["Browser"] != null)
                                tcBrowser = dtTemp.ExtendedProperties["Browser"].ToString();
                            if (dtTemp.ExtendedProperties["RCMachineId"] != null)
                                tcMachine = dtTemp.ExtendedProperties["RCMachineId"].ToString();
                            if ((dtTemp.ExtendedProperties["SauceJobUrl"] != null) && (dtTemp.ExtendedProperties["SauceJobUrl"].ToString() != ""))
                                tcJobResultLocation = dtTemp.ExtendedProperties["SauceJobUrl"].ToString();

                            //Extract date/time information from xml files
开发者ID:Thinksys,项目名称:krypton,代码行数:67,代码来源:LogFile.cs


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