C# Path.GetInvalidFileNameChars的代码示例

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

在ThisIsNotRocketScience提供的Main()方法中,该源代码示例一共有71行, 其中使用了Path.GetInvalidFileNameChars()1次, 并且小编将这些方法高亮显示出来了,希望对您了解Path.GetInvalidFileNameChars()有帮助。 如果您觉得有帮助的话,请帮忙点赞或转发。
该代码示例的点赞次数为3, 点赞数越大, 从某种程度说明这个示例对了解Path.GetInvalidFileNameChars()可能更有帮助。

Path.GetInvalidFileNameChars的代码示例2 - Awake()

    using System.IO;
		#endregion

		#region Messages
		private void Awake()
		{
			m_instance = this;

			canvas = GetComponent();
			rectTransform = (RectTransform) transform;
			windowTR = (RectTransform) window.transform;
			windowLayoutGroup = window.GetComponent();
			filtersDropdownContainer = filtersDropdown.template;
			filterItemTemplate = filtersDropdown.itemText;

			middleViewQuickLinksOriginalSize = middleViewQuickLinks.sizeDelta;

			nullPointerEventData = new PointerEventData( null );

#if !UNITY_EDITOR && ( UNITY_ANDROID || UNITY_IOS || UNITY_WSA || UNITY_WSA_10_0 )
			defaultInitialPath = Application.persistentDataPath;
#else
			defaultInitialPath = Environment.GetFolderPath( Environment.SpecialFolder.MyDocuments );
#endif

#if !UNITY_EDITOR && UNITY_ANDROID
			if( FileBrowserHelpers.ShouldUseSAF )
			{
				// These UI elements have no use in Storage Access Framework mode (Android 10+)
				pathInputField.gameObject.SetActive( false );
				showHiddenFilesToggle.gameObject.SetActive( false );
			}
#endif

			SetExcludedExtensions( excludedExtensions );

			backButton.interactable = false;
			forwardButton.interactable = false;
			upButton.interactable = false;

			backButton.onClick.AddListener( OnBackButtonClicked );
			forwardButton.onClick.AddListener( OnForwardButtonClicked );
			upButton.onClick.AddListener( OnUpButtonClicked );
			moreOptionsButton.onClick.AddListener( OnMoreOptionsButtonClicked );
			submitButton.onClick.AddListener( OnSubmitButtonClicked );
			cancelButton.onClick.AddListener( OnCancelButtonClicked );
			pathInputField.onEndEdit.AddListener( OnPathChanged );
			searchInputField.onValueChanged.AddListener( OnSearchStringChanged );
			filenameInputField.onValidateInput += OnValidateFilenameInput;
			filenameInputField.onValueChanged.AddListener( OnFilenameInputChanged );
			filtersDropdown.onValueChanged.AddListener( OnFilterChanged );
			showHiddenFilesToggle.onValueChanged.AddListener( OnShowHiddenFilesToggleChanged );

			allFilesFilter = new Filter( AllFilesFilterText );
			filters.Add( allFilesFilter );
			filterLabels.Add( allFilesFilter.ToString() );

			invalidFilenameChars = new HashSet( Path.GetInvalidFileNameChars() )
			{
				Path.DirectorySeparatorChar,
				Path.AltDirectorySeparatorChar
			};

			window.Initialize( this );
			listView.SetAdapter( this );

			// Refresh the skin immediately
			m_skinVersion = m_skin.Version;
			RefreshSkin();

			if( !showResizeCursor )
				Destroy( resizeCursorHandler );

#if ENABLE_INPUT_SYSTEM && !ENABLE_LEGACY_INPUT_MANAGER
			// On new Input System, scroll sensitivity is much higher than legacy Input system
			filesScrollRect.scrollSensitivity *= 0.25f;
			quickLinksContainer.GetComponentInParent().scrollSensitivity *= 0.25f;
			filtersDropdownContainer.GetComponent().scrollSensitivity *= 0.25f;
#endif
		}
    

开发者ID: yasirkula,   项目名称: UnitySimpleFileBrowser,   代码行数: 80,   代码来源: FileBrowser.cs

在yasirkula提供的Awake()方法中,该源代码示例一共有80行, 其中使用了Path.GetInvalidFileNameChars()1次, 并且小编将这些方法高亮显示出来了,希望对您了解Path.GetInvalidFileNameChars()有帮助。 如果您觉得有帮助的话,请帮忙点赞或转发。
该代码示例的点赞次数为3, 点赞数越大, 从某种程度说明这个示例对了解Path.GetInvalidFileNameChars()可能更有帮助。

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

在zzzprojects提供的GetCachePath()方法中,该源代码示例一共有79行, 其中使用了Path.GetInvalidFileNameChars()1次, 并且小编将这些方法高亮显示出来了,希望对您了解Path.GetInvalidFileNameChars()有帮助。 如果您觉得有帮助的话,请帮忙点赞或转发。
该代码示例的点赞次数为3, 点赞数越大, 从某种程度说明这个示例对了解Path.GetInvalidFileNameChars()可能更有帮助。

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

在EWSoftware提供的TransformComponent_TopicTransforming()方法中,该源代码示例一共有38行, 其中使用了Path.GetInvalidFileNameChars()1次, 并且小编将这些方法高亮显示出来了,希望对您了解Path.GetInvalidFileNameChars()有帮助。 如果您觉得有帮助的话,请帮忙点赞或转发。
该代码示例的点赞次数为3, 点赞数越大, 从某种程度说明这个示例对了解Path.GetInvalidFileNameChars()可能更有帮助。

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

在huiyadanli提供的txtFileNamePattern_TextChanged()方法中,该源代码示例一共有39行, 其中使用了Path.GetInvalidFileNameChars()1次, 并且小编将这些方法高亮显示出来了,希望对您了解Path.GetInvalidFileNameChars()有帮助。 如果您觉得有帮助的话,请帮忙点赞或转发。
该代码示例的点赞次数为3, 点赞数越大, 从某种程度说明这个示例对了解Path.GetInvalidFileNameChars()可能更有帮助。

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

在huiyadanli提供的GenerateFileName()方法中,该源代码示例一共有85行, 其中使用了Path.GetInvalidFileNameChars()1次, 并且小编将这些方法高亮显示出来了,希望对您了解Path.GetInvalidFileNameChars()有帮助。 如果您觉得有帮助的话,请帮忙点赞或转发。
该代码示例的点赞次数为3, 点赞数越大, 从某种程度说明这个示例对了解Path.GetInvalidFileNameChars()可能更有帮助。

Path.GetInvalidFileNameChars()方法的常见问题及解答

C#中Path.GetInvalidFileNameChars()的常见错误类型及注意事项

Path.GetInvalidFileNameChars的错误类型有很多, 这里就不一一阐述了,本文只列出一些常见的代码示例供参考,大家可以看一下代码中Catch语句中是否有常见的错误捕获及处理。

C#中Path.GetInvalidFileNameChars()的构造函数有哪些

Path.GetInvalidFileNameChars构造函数功能基本类似,只是参数不同; 目前主流的集成开发环境都已经带智能提醒了,如:Visual Studio; 大家可以非常轻松的通过Visual Studio中的智能提醒,了解对应构造函数的用法。

如何使用ChartGPT写一段Path.GetInvalidFileNameChars的代码

你可以在ChartGPT中输入如下的指令:"提供一个如何使用Path.GetInvalidFileNameChars的C#代码示例"
ChartGPT写出的代码和本文中的小编提供的代码的区别。 ChartGPT发展到现在已经非常聪明了,但需要使用这提供非常专业的问题,才可能有比较好的源代码示例; 而本文中, 小编已经帮您列出来基本所有类和所有方法的使用示例, 而且这些示例基本都是一些网络大佬提供的源码,可以更方便的供一些开发菜鸟或者资深开发参考和学习。

Path.GetInvalidFileNameChars所在的类及名称空间

Path.GetInvalidFileNameChars是System.IO下的方法。

Path.GetInvalidFileNameChars怎么使用?

Path.GetInvalidFileNameChars使用上比较简单,可以参考MSDN中的帮助文档,也参考本文中提供的7个使用示例。

Path.GetInvalidFileNameChars菜鸟教程

对于菜鸟来说,本文中提供的7个Path.GetInvalidFileNameChars写法都将非常直观的帮您掌握Path.GetInvalidFileNameChars的用法,是一个不错的参考教程。

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