C# Path.GetFileNameWithoutExtension的代码示例

通过代码示例来学习C# Path.GetFileNameWithoutExtension方法

通过代码示例来学习编程是非常高效的。
1. 代码示例提供了一个具体而直观的学习环境,使初学者能够立即看到编程概念和语法的实际应用。
2. 通过分析和模仿现有的代码实例,初学者可以更好地理解编程逻辑和算法的工作原理。
3. 代码实例往往涵盖了多种编程技巧和最佳实践,通过学习和模仿这些实例,学习者可以逐步掌握如何编写高效、可读性强和可维护的代码。这对于初学者来说,是一种快速提升编程水平的有效途径。


Path.GetFileNameWithoutExtension是C#的System.IO命名空间下中的一个方法, 小编为大家找了一些网络大拿们常见的代码示例,源码中的Path.GetFileNameWithoutExtension() 已经帮大家高亮显示了,大家可以重点学习Path.GetFileNameWithoutExtension() 方法的写法,从而快速掌握该方法的应用。

Path.GetFileNameWithoutExtension的代码示例1 - SearchForGameExe()

    using System.IO;

        string SearchForGameExe(string dirPath)
        {
            List filesToCheck = new List();

            // Try searching for UE4/UE5 specific EXE name
            var allExeFiles = Directory.GetFiles(dirPath, "*.exe", SearchOption.AllDirectories);
            foreach (var filePath in allExeFiles)
            {
                var fileName = Path.GetFileNameWithoutExtension(filePath).ToLower();
                if (fileName.Contains("-win") && fileName.EndsWith("-shipping"))
                    filesToCheck.Add(filePath);
            }

            // blacklist some DLLs that are known to not be relevant
            var blacklistDlls = new string[]
            {
                    "dlsstweak",
                    "igxess",
                    "libxess",
                    "nvngx",
                    "EOSSDK-",
                    "steam_api",
                    "sl.",
                    "D3D12",
                    "dstorage",
                    "PhysX",
                    "NvBlast",
                    "amd_",
                    "PeanutButter."
            };

            if (filesToCheck.Count <= 0)
            {
                // Fetch all EXE/DLL files in the chosen dir
                filesToCheck.AddRange(Directory.GetFiles(dirPath, "*.exe"));
                filesToCheck.AddRange(Directory.GetFiles(dirPath, "*.dll"));
            }

            long dllSizeMinimum = 2_097_152; // 2MB

            // Return largest EXE we find in the specified folder, most likely to be the game EXE
            // TODO: search subdirectories too and recommend user change folder if larger EXE was found?
            FileInfo largest = null;
            foreach (var file in filesToCheck)
            {
                var lowerName = Path.GetFileName(file).ToLower();

                // Check against blacklistDlls array
                if (blacklistDlls.Any(blacklistDll => lowerName.StartsWith(blacklistDll.ToLower())))
                    continue;

                var info = new FileInfo(file);

                if (info.Extension.ToLower() == "dll" && info.Length < dllSizeMinimum)
                    continue;

                if (largest == null || info.Length > largest.Length)
                    largest = info;
            }
            if (largest == null)
                return null;

            return largest.FullName;
        }
    

开发者ID:emoose,项目名称:DLSSTweaks,代码行数:66,代码来源:Main.cs

在SearchForGameExe()方法中,Path的代码示例类中的GetFileNameWithoutExtension的代码示例方法一共出现了1次, 见黄色背景高亮显示的地方,欢迎大家点赞

Path.GetFileNameWithoutExtension的代码示例2 - AutoGenerateSources()

    using System.IO;

        /// 
        /// Automatically generates required sources files for building the Bootstrapper. It is
        /// used to automatically generate the files which, can be generated automatically without
        /// user involvement (e.g. BootstrapperCore.config).
        /// 
        /// The output directory.
        public override void AutoGenerateSources(string outDir)
        {
            //NOTE: while it is tempting, AutoGenerateSources cannot be called during initialization as it is too early.
            //The call must be triggered by Compiler.Build* calls.
            rawAppAssembly = AppAssembly;
            if (rawAppAssembly.EndsWith("%this%"))
            {
                rawAppAssembly = Compiler.ResolveClientAsm(outDir); //NOTE: if a new file is generated then the Compiler takes care for cleaning any temps
                if (Payloads.FirstOrDefault(x => x.SourceFile == "%this%") is Payload payload_this)
                    payload_this.SourceFile = rawAppAssembly;
            }

            string asmName = Path.GetFileNameWithoutExtension(Utils.OriginalAssemblyFile(rawAppAssembly));

            var suppliedConfig = Payloads.Select(x => x.SourceFile).FirstOrDefault(x => Path.GetFileName(x).SameAs("BootstrapperCore.config", true));

            bootstrapperCoreConfig = suppliedConfig;
            if (bootstrapperCoreConfig == null)
            {
                bootstrapperCoreConfig = Path.Combine(outDir, "BootstrapperCore.config");

                sys.File.WriteAllText(bootstrapperCoreConfig,
                                      DefaultBootstrapperCoreConfigContent.Replace("{asmName}", asmName));

                Compiler.TempFiles.Add(bootstrapperCoreConfig);
            }

            // WiX does not check the validity of the BootstrapperCore.config so we need to do it
            try
            {
                var expectedAssemblyName = XDocument.Load(bootstrapperCoreConfig)
                                                    .FindFirst("host")
                                                    .Attribute("assemblyName")
                                                    .Value;

                if (asmName != expectedAssemblyName)
                {
                    Compiler.OutputWriteLine(
                        $"WARNING: It looks like your configured BA assembly name () " +
                        $"from `BootstrapperCore.config` file is not matching the actual assembly name (\"{asmName}\").");
                }
            }
            catch { }
        }
    

开发者ID:oleg-shilo,项目名称:wixsharp,代码行数:52,代码来源:BootstrapperApplication.cs

在AutoGenerateSources()方法中,Path的代码示例类中的GetFileNameWithoutExtension的代码示例方法一共出现了1次, 见黄色背景高亮显示的地方,欢迎大家点赞

Path.GetFileNameWithoutExtension的代码示例3 - BuildCmd()

    using System.IO;

        /// 
        /// Builds the WiX source file and generates batch file capable of building
        /// WiX/MSI bootstrapper with WiX toolset.
        /// 
        /// The project.
        /// The path to the batch file to be created.
        /// Wix compiler/linker cannot be found
        public static string BuildCmd(Bundle project, string path = null)
        {
            if (path == null)
                path = IO.Path.GetFullPath(IO.Path.Combine(project.OutDir, "Build_" + project.OutFileName) + ".cmd");

            path = path.ExpandEnvVars();

            //System.Diagnostics.Debug.Assert(false);
            string wixLocationEnvVar = $"set WixLocation={WixLocation}" + Environment.NewLine;
            string compiler = Utils.PathCombine(WixLocation, "candle.exe");
            string linker = Utils.PathCombine(WixLocation, "light.exe");
            string batchFile = path;

            if (!IO.File.Exists(compiler) || !IO.File.Exists(linker))
            {
                Compiler.OutputWriteLine("Wix binaries cannot be found. Expected location is " + IO.Path.GetDirectoryName(compiler));
                throw new ApplicationException("Wix compiler/linker cannot be found");
            }
            else
            {
                string wxsFile = BuildWxs(project);

                if (!project.SourceBaseDir.IsEmpty())
                    Environment.CurrentDirectory = project.SourceBaseDir;

                string objFile = IO.Path.ChangeExtension(wxsFile, ".wixobj");
                string pdbFile = IO.Path.ChangeExtension(wxsFile, ".wixpdb");

                string extensionDlls = "";
                // note we need to avoid possible duplications cause by non expanded envars
                // %wix_location%\ext.dll vs c:\Program Files\...\ext.dll
                foreach (string dll in project.WixExtensions.DistinctBy(x => x.ExpandEnvVars()))
                    extensionDlls += " -ext \"" + dll + "\"";

                string wxsFiles = "";
                foreach (string file in project.WxsFiles.Distinct())
                    wxsFiles += " \"" + file + "\"";

                var candleOptions = CandleOptions + " " + project.CandleOptions;

                string batchFileContent = wixLocationEnvVar + "\"" + compiler + "\" " + candleOptions + " " + extensionDlls +
                                          " \"" + wxsFile + "\" ";

                string outDir = null;
                if (wxsFiles.IsNotEmpty())
                {
                    batchFileContent += wxsFiles;
                    outDir = IO.Path.GetDirectoryName(wxsFile);
                    // if multiple files are specified candle expect a path for the -out switch
                    // or no path at all (use current directory)
                    // note the '\' character must be escaped twice: as a C# string and as a CMD char
                    if (outDir.IsNotEmpty())
                        batchFileContent += $" -out \"{outDir}\\\\\"";
                }
                else
                    batchFileContent += $" -out \"{objFile}\"";

                batchFileContent += "\r\n";

                string fragmentObjectFiles = project.WxsFiles
                                             .Distinct()
                                             .JoinBy(" ", file => "\"" + outDir.PathCombine(IO.Path.GetFileNameWithoutExtension(file)) + ".wixobj\"");

                string lightOptions = LightOptions + " " + project.LightOptions;

                if (fragmentObjectFiles.IsNotEmpty())
                    lightOptions += " " + fragmentObjectFiles;

                if (path.IsNotEmpty())
                    lightOptions += " -out \"" + IO.Path.ChangeExtension(objFile, ".exe") + "\"";

                batchFileContent += "\"" + linker + "\" " + lightOptions + " \"" + objFile + "\" " + extensionDlls + " -cultures:" + project.Language + "\r\npause";

                batchFileContent = batchFileContent.ExpandEnvVars();

                using (var sw = new IO.StreamWriter(batchFile))
                    sw.Write(batchFileContent);
            }

            return path;
        }
    

开发者ID:oleg-shilo,项目名称:wixsharp,代码行数:90,代码来源:Compiler.Bootstrapper.cs

在BuildCmd()方法中,Path的代码示例类中的GetFileNameWithoutExtension的代码示例方法一共出现了1次, 见黄色背景高亮显示的地方,欢迎大家点赞

Path.GetFileNameWithoutExtension的代码示例4 - AddSplashScreen()

    using System.IO;

        private void AddSplashScreen(IO.StringWriter writer)
        {
            if (SplashScreen != null)
            {
                AddFileCommand(writer, SplashScreen.FileName);

                var keyColor = SplashScreen.KeyColor.IsEmpty
                    ? "-1"
                    : $"0x{SplashScreen.KeyColor.ToArgb() & 0x00FFFFFF:X6}";

                var text = string.Format("advsplash::show {0} {1} {2} {3} \"{4}\"",
                    SplashScreen.Delay.TotalMilliseconds,
                    SplashScreen.FadeIn.TotalMilliseconds,
                    SplashScreen.FadeOut.TotalMilliseconds,
                    keyColor,
                    $@"{PluginsDir}\{IO.Path.GetFileNameWithoutExtension(SplashScreen.FileName)}");

                writer.WriteLine(text);
                // $0 has '1' if the user closed the splash screen early,
                // '0' if everything closed normally, and '-1' if some error occurred.
                writer.WriteLine("Pop $0");
            }
        }
    

开发者ID:oleg-shilo,项目名称:wixsharp,代码行数:25,代码来源:NsisBootstrapper.cs

在AddSplashScreen()方法中,Path的代码示例类中的GetFileNameWithoutExtension的代码示例方法一共出现了1次, 见黄色背景高亮显示的地方,欢迎大家点赞

Path.GetFileNameWithoutExtension的代码示例5 - GetMsiForegroundWindow()

    using System.IO;

        /// 
        /// Gets the msi foreground window.
        /// 
        /// 
        protected virtual IntPtr GetMsiForegroundWindow()
        {
            Process proc = null;

            var bundleUI = Environment.GetEnvironmentVariable("WIXSHARP_SILENT_BA_PROC_ID");
            if (bundleUI != null)
            {
                int id = 0;
                if (int.TryParse(bundleUI, out id))
                    proc = Process.GetProcessById(id);
            }

            var bundlePath = session["WIXBUNDLEORIGINALSOURCE"];
            if (bundlePath.IsNotEmpty())
            {
                try
                {
                    proc = Process.GetProcessesByName(Path.GetFileNameWithoutExtension(bundlePath)).Where(p => p.MainWindowHandle != IntPtr.Zero).FirstOrDefault();
                }
                catch { }
            }

            if (proc == null)
            {
                proc = Process.GetProcessesByName("msiexec").Where(p => p.MainWindowHandle != IntPtr.Zero).FirstOrDefault();
            }

            if (proc != null)
            {
                //IntPtr handle = proc.MainWindowHandle; //old algorithm

                IntPtr handle = MsiWindowFinder.GetMsiDialog(proc.Id);

                Win32.ShowWindow(handle, Win32.SW_RESTORE);
                Win32.SetForegroundWindow(handle);

                return handle;
            }
            else return IntPtr.Zero;
        }
    

开发者ID:oleg-shilo,项目名称:wixsharp,代码行数:46,代码来源:WixCLRDialog.cs

在GetMsiForegroundWindow()方法中,Path的代码示例类中的GetFileNameWithoutExtension的代码示例方法一共出现了1次, 见黄色背景高亮显示的地方,欢迎大家点赞

Path.GetFileNameWithoutExtension的代码示例6 - CreateNewFromImage()

    using System.IO;


        public static BFLIM CreateNewFromImage()
        {
            BFLIM bflim = new BFLIM();
            bflim.CanSave = true;
            bflim.IFileInfo = new IFileInfo();
            bflim.header = new Header();

            OpenFileDialog ofd = new OpenFileDialog();
            ofd.Multiselect = false;
            ofd.Filter = FileFilters.GTX;
            if (ofd.ShowDialog() != DialogResult.OK)
                return null;

            FTEX ftex = new FTEX();
            ftex.ReplaceTexture(ofd.FileName, TEX_FORMAT.BC3_UNORM_SRGB, 1, 0, bflim.SupportedFormats, true,  false, true, false);
            if (ftex.texture != null)
            {
                bflim.Text = $"{Path.GetFileNameWithoutExtension(ofd.FileName)}.bflim";
                bflim.image = new Image();
                bflim.image.Swizzle = (byte)ftex.texture.Swizzle;
                bflim.image.BflimFormat = FormatsWiiU.FirstOrDefault(x => x.Value == ftex.Format).Key;
                if (ftex.UseBc4Alpha)
                    bflim.image.BflimFormat = 16;

                bflim.image.Height = (ushort)ftex.texture.Height;
                bflim.image.Width = (ushort)ftex.texture.Width;

                bflim.Format = FormatsWiiU[bflim.image.BflimFormat];
                bflim.Width = bflim.image.Width;
                bflim.Height = bflim.image.Height;
                bflim.ImageData = ftex.texture.Data;

                bflim.LoadComponents(bflim.Format, ftex.UseBc4Alpha);
            }

            return bflim;
        }
    

开发者ID:KillzXGaming,项目名称:Switch-Toolbox,代码行数:40,代码来源:BFLIM.cs

在CreateNewFromImage()方法中,Path的代码示例类中的GetFileNameWithoutExtension的代码示例方法一共出现了1次, 见黄色背景高亮显示的地方,欢迎大家点赞

Path.GetFileNameWithoutExtension的代码示例7 - ExportAction()

    
        private void ExportAction(object sender, EventArgs args)
        {
            SaveFileDialog sfd = new SaveFileDialog();
            sfd.Filter = "Collada DAE |*.dae;";
            sfd.FileName = System.IO.Path.GetFileNameWithoutExtension(FileName);
            if (sfd.ShowDialog() == DialogResult.OK)
            {
                var model = new STGenericModel();
                var materials = new List();
                var textures = new List();
                foreach (var mesh in Renderer.Meshes)
                    materials.Add(mesh.GetMaterial());
                foreach (var mesh in Renderer.Meshes)
                    mesh.MaterialIndex = materials.IndexOf(mesh.GetMaterial());
                foreach (var tex in Renderer.TextureList)
                    textures.Add(tex);

                model.Materials = materials;
                model.Objects = Renderer.Meshes;

                ExportModelSettings exportDlg = new ExportModelSettings();
                if (exportDlg.ShowDialog() == DialogResult.OK)
                    DAE.Export(sfd.FileName, exportDlg.Settings, model, textures, Skeleton);
            }
        }
    

开发者ID:KillzXGaming,项目名称:Switch-Toolbox,代码行数:26,代码来源:BMD.cs

在ExportAction()方法中,Path的代码示例类中的GetFileNameWithoutExtension的代码示例方法一共出现了1次, 见黄色背景高亮显示的地方,欢迎大家点赞

Path.GetFileNameWithoutExtension的代码示例8 - ReplaceAll()

    using System.IO;

        public static void ReplaceAll(BNTX[] bntxFiles)
        {
            FolderSelectDialog sfd = new FolderSelectDialog();
            if (sfd.ShowDialog() == DialogResult.OK)
            {
                BinaryTextureImporterList importer = new BinaryTextureImporterList();
                List settings = new List();
                List TexturesForImportSettings = new List();

                foreach (string file in System.IO.Directory.GetFiles(sfd.SelectedPath))
                {
                    TextureImporterSettings setting = new TextureImporterSettings();

                    string FileName = System.IO.Path.GetFileNameWithoutExtension(file);

                    string ext = Utils.GetExtension(file);

                    foreach (var bntx in bntxFiles)
                    {
                        foreach (TextureData node in bntx.Textures.Values)
                        {
                            var DefaultFormat = node.Format;

                            if (FileName == node.Text)
                            {
                                switch (ext)
                                {
                                    case ".bftex":
                                        node.Texture.Import(file);
                                        node.LoadOpenGLTexture();
                                        break;
                                    case ".dds":
                                    case ".dds2":
                                        setting.LoadDDS(file, null, node);
                                        node.ApplyImportSettings(setting, STCompressionMode.Normal, false);
                                        break;
                                    case ".astc":
                                        setting.LoadASTC(file);
                                        node.ApplyImportSettings(setting, STCompressionMode.Normal, false);
                                        break;
                                    case ".png":
                                    case ".tga":
                                    case ".tiff":
                                    case ".gif":
                                    case ".jpg":
                                    case ".jpeg":
                                        TexturesForImportSettings.Add(node);
                                        setting.LoadBitMap(file);
                                        importer.LoadSetting(setting);
                                        if (!STGenericTexture.IsAtscFormat(DefaultFormat))
                                            setting.Format = TextureData.GenericToBntxSurfaceFormat(DefaultFormat);

                                        settings.Add(setting);
                                        break;
                                    default:
                                        return;
                                }
                            }
                        }
                    }
                }

                if (settings.Count == 0)
                {
                    importer.Close();
                    importer.Dispose();
                    return;
                }

                int settingsIndex = 0;
                if (importer.ShowDialog() == DialogResult.OK)
                {
                    foreach (TextureData node in TexturesForImportSettings)
                        node.ApplyImportSettings(settings[settingsIndex++], importer.CompressionMode, importer.MultiThreading);
                }

                TexturesForImportSettings.Clear();
            }
        }
    

开发者ID:KillzXGaming,项目名称:Switch-Toolbox,代码行数:81,代码来源:BNTX.cs

在ReplaceAll()方法中,Path的代码示例类中的GetFileNameWithoutExtension的代码示例方法一共出现了1次, 见黄色背景高亮显示的地方,欢迎大家点赞

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