C# Path.GetInvalidFileNameChars的代码示例
通过代码示例来学习C# Path.GetInvalidFileNameChars方法
通过代码示例来学习编程是非常高效的。
1. 代码示例提供了一个具体而直观的学习环境,使初学者能够立即看到编程概念和语法的实际应用。
2. 通过分析和模仿现有的代码实例,初学者可以更好地理解编程逻辑和算法的工作原理。
3. 代码实例往往涵盖了多种编程技巧和最佳实践,通过学习和模仿这些实例,学习者可以逐步掌握如何编写高效、可读性强和可维护的代码。这对于初学者来说,是一种快速提升编程水平的有效途径。
Path.GetInvalidFileNameChars是C#的System.IO命名空间下中的一个方法, 小编为大家找了一些网络大拿们常见的代码示例,源码中的Path.GetInvalidFileNameChars() 已经帮大家高亮显示了,大家可以重点学习Path.GetInvalidFileNameChars() 方法的写法,从而快速掌握该方法的应用。
Path.GetInvalidFileNameChars的代码示例1 - Main()
using System.IO; static void Main(string[] args) { string inputfolder = "."; if (args.Length > 0) { inputfolder = args[0]; } string outputfolder = ""; if (args.Length > 1) { outputfolder = args[1]; if (Directory.Exists(outputfolder) == false) Directory.CreateDirectory(outputfolder); } if (Directory.Exists(inputfolder) == false) { Console.WriteLine("Directory not found!"); return; } var Generated = ScanFolder(inputfolder, outputfolder); { int c = 0; foreach (var a in Generated.OrderBy(x => x.Label.ToLower())) { File.Delete(a.Outputfilename); Console.WriteLine("Creating icon: \"{0}\"", a.Label); Artwork.TINRSArtWorkRenderer.SaveMultiIcon(a.Outputfilename, a.Label, (float)c/(float)Generated.Count); if (outputfolder.Length > 0) { string fileName = a.Label + ".ico"; foreach (char cc in System.IO.Path.GetInvalidFileNameChars()) { fileName = fileName.Replace(cc, '_'); } Artwork.TINRSArtWorkRenderer.SaveMultiIcon(Path.Combine(outputfolder, fileName), a.Label, (float)c / (float)Generated.Count); } c++; } } if (outputfolder.Length > 0) { int iconsize = 128; int iconspacing = 10; int Size = (int)Math.Ceiling(Math.Sqrt(Generated.Count)); Bitmap B = new Bitmap((iconsize + iconspacing)* Size, (iconsize + iconspacing) * Size); Graphics T = Graphics.FromImage(B); T.Clear(Color.Black); int c = 0; foreach(var a in Generated.OrderBy(x => x.Label.ToLower())) { Bitmap C = new Bitmap(iconsize, iconsize); Graphics.FromImage(C).Clear(Color.Transparent); Artwork.TINRSArtWorkRenderer.DrawIcon(iconsize, iconsize, Graphics.FromImage(C), a.Label,(float)c/(float)Generated.Count ); T.DrawImage(C, (c % Size) * (iconsize + iconspacing) + iconspacing / 2, (c / Size) * (iconsize + iconspacing) + iconspacing / 2); c++; } B.Save(Path.Combine(outputfolder, "IconSheet.png")); } }
开发者ID:ThisIsNotRocketScience,项目名称:GerberTools,代码行数:71,代码来源:IconScanner.cs
在Main()方法中,Path的代码示例类中的GetInvalidFileNameChars的代码示例方法一共出现了1次, 见黄色背景高亮显示的地方,欢迎大家点赞
Path.GetInvalidFileNameChars的代码示例2 - Awake()
using System.IO; #endregion #region Messages private void Awake() { m_instance = this; canvas = GetComponent
开发者ID:yasirkula,项目名称:UnitySimpleFileBrowser,代码行数:80,代码来源:FileBrowser.cs
在Awake()方法中,Path的代码示例类中的GetInvalidFileNameChars的代码示例方法一共出现了1次, 见黄色背景高亮显示的地方,欢迎大家点赞
Path.GetInvalidFileNameChars的代码示例3 - GetCachePath()
using System.IO; #endif #if NET45 || NETSTANDARD1_3 || NETSTANDARD1_6 ///
/// Gets an HTML document from an Internet resource and saves it to the specified file. Understands Proxies /// /// The requested URL, such as "http://Myserver/Mypath/Myfile.asp". /// The location of the file where you want to save the document. /// /// The HTTP method used to open the connection, such as GET, POST, PUT, or PROPFIND. /// public void Get(string url, string path, IWebProxy proxy, ICredentials credentials, string method) { Uri uri = new Uri(url); #if !(NETSTANDARD1_3 || NETSTANDARD1_6) if ((uri.Scheme == Uri.UriSchemeHttps) || (uri.Scheme == Uri.UriSchemeHttp)) #else // TODO: Check if UriSchemeHttps is still internal in NETSTANDARD 2.0 if ((uri.Scheme == "https") || (uri.Scheme == "http")) #endif { Get(uri, method, path, null, proxy, credentials); } else { throw new HtmlWebException("Unsupported uri scheme: '" + uri.Scheme + "'."); } } #endif ////// Gets the cache file path for a specified url. /// /// The url fo which to retrieve the cache path. May not be null. ///The cache file path. public string GetCachePath(Uri uri) { if (uri == null) { throw new ArgumentNullException("uri"); } if (!UsingCache) { throw new HtmlWebException("Cache is not enabled. Set UsingCache to true first."); } string cachePath; if (uri.AbsolutePath == "/") { cachePath = Path.Combine(_cachePath, ".htm"); } else { string absolutePathWithoutBadChar = uri.AbsolutePath; string invalid = new string(Path.GetInvalidFileNameChars()) + new string(Path.GetInvalidPathChars()); foreach (char c in invalid) { absolutePathWithoutBadChar = absolutePathWithoutBadChar.Replace(c.ToString(), ""); } if (uri.AbsolutePath[uri.AbsolutePath.Length - 1] == Path.AltDirectorySeparatorChar) { cachePath = Path.Combine(_cachePath, (uri.Host + absolutePathWithoutBadChar.TrimEnd(Path.AltDirectorySeparatorChar)).Replace('/', '\\') + ".htm"); } else { cachePath = Path.Combine(_cachePath, (uri.Host + absolutePathWithoutBadChar.Replace('/', '\\'))); } } return cachePath; }
开发者ID:zzzprojects,项目名称:html-agility-pack,代码行数:79,代码来源:HtmlWeb.cs
在GetCachePath()方法中,Path的代码示例类中的GetInvalidFileNameChars的代码示例方法一共出现了1次, 见黄色背景高亮显示的地方,欢迎大家点赞
Path.GetInvalidFileNameChars的代码示例4 - TransformComponent_TopicTransforming()
using System.IO; ///
/// Save the raw content just before transforming so that all other components have had a chance to /// add and modify the content such as the Syntax Component. /// /// The sender of the event /// The event arguments private void TransformComponent_TopicTransforming(object sender, EventArgs e) { // Don't bother if not a transforming event or not in our group if(!(e is ApplyingChangesEventArgs ac) || ac.GroupId != this.GroupId || ac.ComponentId != "Transform Component") { return; } if(ac.Document != null) { StringBuilder filename = new StringBuilder(ac.Key); foreach(char c in Path.GetInvalidFileNameChars()) if(ac.Key.IndexOf(c) != -1) filename.Replace(c, '_'); string xmlFile = Path.Combine(rawDocsPath, filename.ToString()); if(xmlFile.Length > 250) xmlFile = xmlFile.Substring(0, 250); xmlFile += ".xml"; using(XmlWriter writer = XmlWriter.Create(xmlFile, settings)) { ac.Document.Save(writer); } } }
开发者ID:EWSoftware,项目名称:SHFB,代码行数:38,代码来源:TransformDocumentDumpComponent.cs
在TransformComponent_TopicTransforming()方法中,Path的代码示例类中的GetInvalidFileNameChars的代码示例方法一共出现了1次, 见黄色背景高亮显示的地方,欢迎大家点赞
Path.GetInvalidFileNameChars的代码示例5 - txtFileNamePattern_TextChanged()
using System.IO; private void txtFileNamePattern_TextChanged(object sender, EventArgs e) { // 合法性检测并输出到预览 // Path.GetInvalidFileNameChars() eq [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 34, 60, 62, 124, 58, 42, 63, 92, 47] char[] InvalidFileNameChars = { '\0', '\x01', '\x02', '\x03', '\x04', '\x05', '\x06', '\x07', '\x08', '\t', '\n', '\x0b', '\x0c', '\r', '\x0e', '\x0f', '\x10', '\x11', '\x12', '\x13', '\x14', '\x15', '\x16', '\x17', '\x18', '\x19', '\x1a', '\x1b', '\x1c', '\x1d', '\x1e', '\x1f', '"', '<', '>', '|', ':', '*', '?', '/' }; int lastSplitCharIndex = txtFileNamePattern.Text.LastIndexOf('\\') + 1; string folder, filename; if (lastSplitCharIndex >= 0) { folder = txtFileNamePattern.Text.Substring(0, lastSplitCharIndex); filename = txtFileNamePattern.Text.Substring(lastSplitCharIndex, txtFileNamePattern.Text.Length - lastSplitCharIndex); Settings.Default.fileNameFolder = folder; Settings.Default.fileNamePattern = folder.EndsWith("\\") ? folder : folder + "\\" + filename; Settings.Default.fileNamePatternPure = filename; } else { filename = txtFileNamePattern.Text; folder = ""; } if (filename.IndexOfAny(InvalidFileNameChars) >= 0) { lblPreviewResult.Text = Resources.Strings.TipInvalidFileNameChars; } else { try { lblPreviewResult.Text = PathGenerator.GenerateDefaultFileName(folder, filename); } catch (Exception ex) { lblPreviewResult.Text = ex.Message; } } }
开发者ID:huiyadanli,项目名称:PasteEx,代码行数:39,代码来源:FormSetting.cs
在txtFileNamePattern_TextChanged()方法中,Path的代码示例类中的GetInvalidFileNameChars的代码示例方法一共出现了1次, 见黄色背景高亮显示的地方,欢迎大家点赞
Path.GetInvalidFileNameChars的代码示例6 - GenerateFileName()
using System.IO; ///
/// Save File Name /// /// /// ///public static string GenerateFileName(string folder, string extension) { folder = folder.EndsWith("\\") ? folder : folder + "\\"; int slashCount = System.Text.RegularExpressions.Regex.Matches(Properties.Settings.Default.fileNameFolder, "\\\\").Count; string[] __ = Properties.Settings.Default.fileNameFolder.Split('\\'); string[] _ = new string[slashCount]; for (int j = 0; j < slashCount; j++) { _[j] = GenerateWithPattern(__[j]); } if (_.Length > 0) { foreach (var k in _) { folder += k + "\\"; } } // if folder doesn't exists if (!Directory.Exists(folder)) { Directory.CreateDirectory(folder); } // Use file name pattern string defaultFileName = null; string pureFileNamePattern = Properties.Settings.Default.fileNamePatternPure; if (string.IsNullOrEmpty(pureFileNamePattern)) { pureFileNamePattern = defaultFileNamePattern.Substring(defaultFileNamePattern.LastIndexOf('\\')+1); } if (pureFileNamePattern.IndexOfAny(Path.GetInvalidFileNameChars()) < 0) { try { defaultFileName = GenerateDefaultFileName(folder, pureFileNamePattern); } catch { defaultFileName = null; } } if (string.IsNullOrEmpty(defaultFileName)) { defaultFileName = GenerateDefaultFileName(folder, defaultFileNamePattern); } // Generate file name string path = folder + defaultFileName + "." + extension; string result; string newFileName = defaultFileName; int i = 0; while (true) { if (File.Exists(path)) { newFileName = defaultFileName + " (" + ++i + ")"; path = folder + newFileName + "." + extension; } else { result = newFileName; break; } if (i > 233) { result = "Default"; break; } } return result; }
开发者ID:huiyadanli,项目名称:PasteEx,代码行数:85,代码来源:PathGenerator.cs
在GenerateFileName()方法中,Path的代码示例类中的GetInvalidFileNameChars的代码示例方法一共出现了1次, 见黄色背景高亮显示的地方,欢迎大家点赞
Path.GetInvalidFileNameChars的代码示例7 - SanitizePath()
using System.IO; public static string SanitizePath(string path, string replaceWith = "") { string root = GetPathRoot(path); if (!string.IsNullOrEmpty(root)) { path = path.Substring(root.Length); } char[] invalidChars = Path.GetInvalidFileNameChars().Except(new char[] { Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar }).ToArray(); path = SanitizeFileName(path, replaceWith, invalidChars); return root + path; }
开发者ID:ShareX,项目名称:ShareX,代码行数:16,代码来源:FileHelpers.cs
在SanitizePath()方法中,Path的代码示例类中的GetInvalidFileNameChars的代码示例方法一共出现了1次, 见黄色背景高亮显示的地方,欢迎大家点赞
本文中的Path.GetInvalidFileNameChars方法示例由csref.cn整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。