C# File.Exists的代码示例

通过代码示例来学习C# File.Exists方法

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


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

File.Exists的代码示例1 - SearchDlssTweaksDlls()

    using System.IO;

        string[] SearchDlssTweaksDlls(string path)
        {
            var dlls = new List();
            foreach (var filename in DlssTweaksDllFilenames)
            {
                try
                {
                    var filepath = Path.Combine(path, filename);
                    if (!File.Exists(filepath))
                        continue;

                    FileVersionInfo fileInfo = FileVersionInfo.GetVersionInfo(filepath);
                    if (fileInfo.ProductName != "DLSSTweaks")
                        continue;

                    dlls.Add(filepath);
                }
                catch
                {
                    continue;
                }
            }
            return dlls.ToArray();
        }
    

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

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

File.Exists的代码示例2 - Main()

    using System.IO;
        public static void Main(string[] args)
        {
            ArgumentParser _parser = new ArgumentParser(args);

            if (args.Length <= 0 || _parser.GetOrDefault("h", "help") == "true") {
                Help();
            }


            if (_parser.GetOrDefault("f", "null") != "null") {
                _pePath = _parser.GetOrDefault("f", "null");
                _encKey = _parser.GetOrDefault("e", "null");
                _pid = _parser.GetOrDefault("pid", "null");

                if (_pePath == "null") Help();
                if (_pid == "null") Help();
            }

            else {
                Help();
            }

            if (!File.Exists(_pePath)) Help();

            Console.WriteLine("[+]:Loading/Parsing PE File '{0}'", _pePath);
            Console.WriteLine();

            byte[] _peBlob = Utils.Read(_pePath);
            int _dataOffset = Utils.scanPattern(_peBlob, _tag);

            Console.WriteLine("[+]:Scanning for Shellcode...");
            if ( _dataOffset == -1) {
                Console.WriteLine("Could not locate data or shellcode");
                Environment.Exit(0);
            }

            Stream stream = new MemoryStream(_peBlob);
            long pos = stream.Seek(_dataOffset + _tag.Length, SeekOrigin.Begin);
            Console.WriteLine("[+]: Shellcode located at {0:x2}", pos);
            byte[] shellcode = new byte[_peBlob.Length - (pos + _tag.Length)];
            stream.Read(shellcode, 0, (_peBlob.Length)- ((int)pos + _tag.Length));
            byte[] _data = Utils.Decrypt(shellcode, _encKey);
            
            stream.Close();

            //Execute shellcode (just a basic/vanilla local shellcode injection logic, make sure to CHANGE this and use your custom shellcode loader.
            
            //CreateThread
            //ExecShellcode(_data);

            //CreateRemoteThread 
            Loader.rexec(Convert.ToInt32(_pid), _data);
           

            }
    

开发者ID:med0x2e,项目名称:SigFlip,代码行数:56,代码来源:Program.cs

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

File.Exists的代码示例3 - GetFilesFromFile()

    using System.IO;

        private static IEnumerable GetFilesFromFile(string fileName, out string error)
        {
            error = null;
            if (string.IsNullOrWhiteSpace(fileName))
            {
                return Enumerable.Empty();
            }

            if (!File.Exists(fileName))
            {
                error = string.Format("Could not find '{0}' list file.", fileName);
                return Enumerable.Empty();
            }

            return File.ReadAllLines(fileName)
                        .Select(line => line.Trim());
        }
    

开发者ID:microsoft,项目名称:VFSForGit,代码行数:19,代码来源:BlobPrefetcher.cs

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

File.Exists的代码示例4 - GetSourceIndex()

    using System.IO;

        private Index GetSourceIndex()
        {
            string indexPath = Path.Combine(this.Enlistment.DotGitRoot, GVFSConstants.DotGit.IndexName);

            if (File.Exists(indexPath))
            {
                Index output = new Index(this.Enlistment.EnlistmentRoot, this.Tracer, indexPath, readOnly: true);
                output.Parse();
                return output;
            }

            return null;
        }
    

开发者ID:microsoft,项目名称:VFSForGit,代码行数:15,代码来源:CheckoutPrefetcher.cs

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

File.Exists的代码示例5 - HandleAllFileDeleteOperations()

    using System.IO;

        private void HandleAllFileDeleteOperations()
        {
            string path;
            while (this.diff.FileDeleteOperations.TryDequeue(out path))
            {
                if (this.HasFailures)
                {
                    return;
                }

                try
                {
                    if (File.Exists(path))
                    {
                        File.Delete(path);
                    }

                    Interlocked.Increment(ref this.fileDeleteCount);
                }
                catch (Exception ex)
                {
                    EventMetadata metadata = new EventMetadata();
                    metadata.Add("Operation", "DeleteFile");
                    metadata.Add("Path", path);
                    this.tracer.RelatedError(metadata, ex.Message);
                    this.HasFailures = true;
                }
            }
        }
    

开发者ID:microsoft,项目名称:VFSForGit,代码行数:31,代码来源:CheckoutStage.cs

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

File.Exists的代码示例6 - Execute()

    using System.IO;

        public override bool Execute()
        {
            string templateFilePath = this.Template.ItemSpec;
            IDictionary properties = ParseProperties(this.Template.GetMetadata("Properties"));

            string outputFileDirectory = Path.GetDirectoryName(this.OutputFile);

            if (!File.Exists(templateFilePath))
            {
                this.Log.LogError("Failed to find template file '{0}'.", templateFilePath);
                return false;
            }

            // Copy the template to the destination to keep the same file mode bits/ACLs as the template
            File.Copy(templateFilePath, this.OutputFile, true);

            this.Log.LogMessage(MessageImportance.Low, "Reading template contents");
            string template = File.ReadAllText(this.OutputFile);

            this.Log.LogMessage(MessageImportance.Normal, "Compiling template '{0}'", templateFilePath);
            string compiled = Compile(template, properties);

            if (!Directory.Exists(outputFileDirectory))
            {
                this.Log.LogMessage(MessageImportance.Low, "Creating output directory '{0}'", outputFileDirectory);
                Directory.CreateDirectory(outputFileDirectory);
            }

            this.Log.LogMessage(MessageImportance.Normal, "Writing compiled template to '{0}'", this.OutputFile);
            File.WriteAllText(this.OutputFile, compiled);

            this.CompiledTemplate = new TaskItem(this.OutputFile, this.Template.CloneCustomMetadata());

            return true;
        }
    

开发者ID:microsoft,项目名称:VFSForGit,代码行数:37,代码来源:CompileTemplatedFile.cs

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

File.Exists的代码示例7 - CopyFile()

    using System.IO;

        private void CopyFile(
            string sourceRoot,
            string targetRoot,
            string fileName)
        {
            string sourceFile = Path.Combine(sourceRoot, fileName);
            string targetFile = Path.Combine(targetRoot, fileName);

            try
            {
                if (!File.Exists(sourceFile))
                {
                    return;
                }

                File.Copy(sourceFile, targetFile);
            }
            catch (Exception e)
            {
                this.WriteMessage(
                    string.Format(
                        "Failed to copy file {0} in {1} with exception {2}",
                        fileName,
                        sourceRoot,
                        e));
            }
        }
    

开发者ID:microsoft,项目名称:VFSForGit,代码行数:29,代码来源:DiagnoseVerb.cs

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

File.Exists的代码示例8 - RunFastFetch()

    using System.IO;

        private ProcessResult RunFastFetch(string args)
        {
            args = args + " --verbose";

            string fastfetch = Path.Combine(Settings.Default.CurrentDirectory, "FastFetch.exe");

            File.Exists(fastfetch).ShouldBeTrue($"{fastfetch} did not exist.");
            Console.WriteLine($"Using {fastfetch}");

            ProcessStartInfo processInfo = new ProcessStartInfo(fastfetch);
            processInfo.Arguments = args;
            processInfo.WorkingDirectory = this.fastFetchRepoRoot;
            processInfo.UseShellExecute = false;
            processInfo.RedirectStandardOutput = true;
            processInfo.RedirectStandardError = true;

            ProcessResult result = ProcessHelper.Run(processInfo);

            return result;
        }
    

开发者ID:microsoft,项目名称:VFSForGit,代码行数:22,代码来源:FastFetchTests.cs

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

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