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


C# FileSystem.FileExists方法代码示例

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


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

示例1: FileExists

 public void FileExists()
 {
     var curDirectory = Directory.GetCurrentDirectory();
     var existingFile = Path.Combine(curDirectory, "../../" + fileName);
     var fileSystem = new FileSystem();
     Assert.IsTrue(fileSystem.FileExists(existingFile));
     var notExistingFile = Path.Combine(curDirectory, "../../" + notExisting);
     Assert.IsFalse(fileSystem.FileExists(notExistingFile));
 }
开发者ID:stormleoxia,项目名称:lx,代码行数:9,代码来源:FileSystemTest.cs

示例2: Correctly_Reports_File_Exists

		public void Correctly_Reports_File_Exists()
		{
			writeSampleFile();

			IFileSystem fileSystem = new FileSystem(null);

			Assert.AreEqual(true, fileSystem.FileExists("test.txt"));
			Assert.AreEqual(false, fileSystem.FileExists("nonExistentFile.txt"));
		}
开发者ID:joaomajesus,项目名称:Tarantino,代码行数:9,代码来源:FileSystemTester.cs

示例3: Test_FileSystem_That_File_Delete_Removes_File

        public void Test_FileSystem_That_File_Delete_Removes_File()
        {
            var fileSystem = new FileSystem();
            var path = Path.Combine(TestContext.DeploymentDirectory, @"IO\1.txt");
            fileSystem.DeleteFile(path);
            Assert.IsFalse(fileSystem.FileExists(path));

            // cleanup
            using(fileSystem.OpenFile(path, FileMode.OpenOrCreate)) {; }
            Assert.IsTrue(fileSystem.FileExists(path));
        }
开发者ID:patrickhuber,项目名称:Cyrus,代码行数:11,代码来源:FileSystemTests.cs

示例4: ForSolution

        public static PersistenceExpression<Solution> ForSolution(Solution target)
        {
            var file = "{0}-{1}.config".ToFormat(typeof(Solution).Name, Guid.NewGuid());
            var fileSystem = new FileSystem();

            if (fileSystem.FileExists(file))
            {
                fileSystem.DeleteFile(file);
            }

            var writer = ObjectBlockWriter.Basic(new RippleBlockRegistry());
            var contents = writer.Write(target);
            Debug.WriteLine(contents);
            fileSystem.WriteStringToFile(file, contents);

            var reader = SolutionLoader.Reader();

            var specification = new PersistenceSpecification<Solution>(x =>
            {
                var fileContents = fileSystem.ReadStringFromFile(file);
                var readValue = Solution.Empty(); 
                reader.Read(readValue, fileContents);

                fileSystem.DeleteFile(file);

                return readValue;
            });

            specification.Original = target;

            return new PersistenceExpression<Solution>(specification);
        }
开发者ID:modulexcite,项目名称:ripple,代码行数:32,代码来源:CheckObjectBlockPersistence.cs

示例5: LoadFrom

        public static SolutionConfig LoadFrom(string directory)
        {
            var fileSystem = new FileSystem();
            var file = directory.AppendPath(FileName);

            return fileSystem.FileExists(file)
                ? fileSystem.LoadFromFile<SolutionConfig>(file)
                : null;
        }
开发者ID:bobpace,项目名称:ripple,代码行数:9,代码来源:SolutionConfig.cs

示例6: buildDriver

        protected override IWebDriver buildDriver()
        {
            var fileSystem = new FileSystem();
            var settings = StoryTellerEnvironment.Get<SerenityEnvironment>();

            return fileSystem.FileExists(settings.WorkingDir, File)
                ? new ChromeDriver(settings.WorkingDir)
                : new ChromeDriver();
        }
开发者ID:rizowski,项目名称:Serenity,代码行数:9,代码来源:ChromeBrowser.cs

示例7: CompressingJpgResultsInSmallerFile

        public void CompressingJpgResultsInSmallerFile()
        {
            // Arrange
            var fileSystem = new FileSystem();
            const string fileToCompress = TestConstants.ExistingJpgFullFileName;
            var compressor = new JpgCompressor();
            const string newFileName = "CompressedResult.jpg";

            // Act
            compressor.Compress(fileToCompress, newFileName);

            // Assert
            Assert.IsTrue(fileSystem.FileExists(fileToCompress));
            Assert.IsTrue(fileSystem.FileExists(newFileName));
            Assert.IsTrue(fileSystem.GetFileLength(fileToCompress) > 0);
            Assert.IsTrue(fileSystem.GetFileLength(newFileName) > 0);
            Assert.IsTrue(fileSystem.GetFileLength(fileToCompress) > fileSystem.GetFileLength(newFileName));
        }
开发者ID:JMnITup,项目名称:PictureHandler,代码行数:18,代码来源:CompressionTests.cs

示例8: ReadFrom

        public static IEnumerable<Input> ReadFrom(string directory)
        {
            var fileSystem = new FileSystem();
            string file = directory.AppendPath(File);
            if (!fileSystem.FileExists(file))
            {
                return Enumerable.Empty<Input>();
            }

            return ReadFromFile(file);
        }
开发者ID:awelburn,项目名称:FubuCsProjFile,代码行数:11,代码来源:Input.cs

示例9: buildDriver

        protected override IWebDriver buildDriver()
        {
            var fileSystem = new FileSystem();
            var settings = StoryTellerEnvironment.Get<SerenityEnvironment>();

            if (fileSystem.FileExists(settings.WorkingDir, File))
            {
                return new PhantomJSDriver(settings.WorkingDir);
            }

            return new PhantomJSDriver(AppDomain.CurrentDomain.BaseDirectory);
        }
开发者ID:rizowski,项目名称:Serenity,代码行数:12,代码来源:PhantomBrowser.cs

示例10: TryHandleCommandAsync

        public async Task<bool> TryHandleCommandAsync(IImmutableSet<IProjectTree> nodes, long commandId, bool focused, long commandExecuteOptions, IntPtr variantArgIn, IntPtr variantArgOut) {
            if (commandId == RPackageCommandId.icmdSourceSelectedFiles || commandId == RPackageCommandId.icmdSourceSelectedFilesWithEcho) {
                bool echo = commandId == RPackageCommandId.icmdSourceSelectedFilesWithEcho;
                
                IFileSystem fs = new FileSystem();
                IEnumerable<string> rFiles = Enumerable.Empty<string>();

                var workflow = _interactiveWorkflowProvider.GetOrCreate();
                try {
                    var session = workflow.RSession;
                    if (session.IsRemote) {
                        var files = nodes.GetSelectedNodesPaths().Where(x =>
                                   Path.GetExtension(x).EqualsIgnoreCase(RContentTypeDefinition.FileExtension) &&
                                   fs.FileExists(x));

                        var properties = _configuredProject.Services.ExportProvider.GetExportedValue<ProjectProperties>();
                        string projectDir = Path.GetDirectoryName(_configuredProject.UnconfiguredProject.FullPath);
                        string projectName = properties.GetProjectName();
                        string remotePath = await properties.GetRemoteProjectPathAsync();

                        await SendToRemoteAsync(files, projectDir, projectName, remotePath, CancellationToken.None);

                        rFiles = files.Select(p => p.MakeRelativePath(projectDir).ProjectRelativePathToRemoteProjectPath(remotePath, projectName));
                    } else {
                        rFiles = nodes.GetSelectedNodesPaths().Where(x =>
                                   Path.GetExtension(x).EqualsIgnoreCase(RContentTypeDefinition.FileExtension) &&
                                   fs.FileExists(x));
                    }

                    workflow.Operations.SourceFiles(rFiles, echo);
                } catch (IOException ex) {
                    _appShell.ShowErrorMessage(string.Format(CultureInfo.InvariantCulture, Resources.Error_CannotTransferFile, ex.Message));
                } 
                catch (RHostDisconnectedException) {
                    workflow.ActiveWindow.InteractiveWindow.WriteErrorLine(Resources.Error_CannotTransferNoRSession);
                }
                return true;
            }
            return false;
        }
开发者ID:Microsoft,项目名称:RTVS,代码行数:40,代码来源:SourceFilesCommand.cs

示例11: writes_both_the_update_and_rollback_files

        public void writes_both_the_update_and_rollback_files()
        {
            StoreOptions(_ =>
            {
                // This is enough to tell Marten that the User
                // document is persisted and needs schema objects
                _.Schema.For<User>();

                // Lets Marten know that the event store is active
                _.Events.AddEventType(typeof(MembersJoined));
            });

            var fileSystem = new FileSystem();
            fileSystem.DeleteDirectory(@"bin\patches");
            fileSystem.CreateDirectory(@"bin\patches");

            // SAMPLE: write-patch
            // Write the patch SQL file to the @"bin\patches" directory
            theStore.Schema.WritePatch(@"bin\patches".AppendPath("1.initial.sql"));
            // ENDSAMPLE

            fileSystem.FileExists(@"bin\patches".AppendPath("1.initial.sql"));
            fileSystem.FileExists(@"bin\patches".AppendPath("1.initial.drop.sql"));
        }
开发者ID:danielmarbach,项目名称:marten,代码行数:24,代码来源:WritePatch_smoke_tests.cs

示例12: TestSubscription

		public async Task TestSubscription()
		{
			var fileSystem = new FileSystem(TestContext.TestRunDirectory);
			fileSystem.RemoveFile(TestFileName);

			Assert.AreEqual(false, fileSystem.FileExists(TestFileName));

			var c = new TaskCompletionSource<IFileInfo>();
			using (await fileSystem.SubscribeAsync(TestFilePattern, s => c.TrySetResult(s)).ConfigureAwait(false))
			{
				using (var writer = new StreamWriter(fileSystem.OpenWrite(TestFileName)))
				{
					writer.BaseStream.SetLength(0);
					writer.Write("123456789");
				}

				var result = await c.Task.ConfigureAwait(false);
				Assert.AreEqual(TestFileName.ToString(), Path.GetFileName(result.FilePath.ToString()));
			}
		}
开发者ID:namics,项目名称:TerrificNet,代码行数:20,代码来源:FileSystemSubscriptionTest.cs

示例13: TestSubscription

		public async Task TestSubscription()
		{
			var fileSystem = new FileSystem(PathUtility.GetDirectory());
			fileSystem.RemoveFile(TestFileName);

			Assert.Equal(false, fileSystem.FileExists(TestFileName));

			var c = new TaskCompletionSource<FileChangeEventArgs>();
			using (fileSystem.Subscribe(GlobPattern.All, s => c.TrySetResult(s)))
			{
				using (var writer = new StreamWriter(fileSystem.OpenWrite(TestFileName)))
				{
					writer.BaseStream.SetLength(0);
					writer.Write("123456789");
				}

				var result = await c.Task.ConfigureAwait(false);
				Assert.Equal(TestFileName.ToString(), Path.GetFileName(result.FileInfo.FilePath.ToString()));
			}
		}
开发者ID:TerrificNet,项目名称:TerrificNet,代码行数:20,代码来源:FileSystemSubscriptionTest.cs

示例14: ReadFrom

        public static Profile ReadFrom(DeploymentSettings settings, string profileName, string settingsProfileName = null)
        {
            var profile = new Profile(profileName);
            var profileFile = settings.ProfileFileNameFor(profileName);

            var fileSystem = new FileSystem();
            if (!fileSystem.FileExists(profileFile))
            {
                var sb = new StringBuilder();
                sb.AppendFormat("Couldn't find the profile '{0}'", profileFile);
                sb.AppendLine();
                sb.AppendLine("Looked in:");
                settings.Directories.Each(d => sb.AppendLine("  {0}".ToFormat(d)));

                throw new Exception(sb.ToString());
            }

            // Settings profile goes first
            if (settingsProfileName != null)
            {
                profile.AddProfileDependency(settingsProfileName);
            }

            fileSystem.ReadTextFile(profileFile, profile.ReadText);

            profile._childProfileNames.Each(childName =>
                {
                    var childProfile = ReadFrom(settings, childName);
                    profile._childProfiles.Add(childProfile);
                    childProfile.Data.AllKeys.Each(childKey =>
                        {
                            // do not override main profile settings from dependencies.
                            // NOTE: Has(childKey) doesn't work here because SettingsData has a weird inner dictionary with a special key structure
                            if (profile.Data.AllKeys.Any(k => k == childKey)) return;

                            profile.Data[childKey] = childProfile.Data[childKey];
                        });
                });

            return profile;
        }
开发者ID:DarthFubuMVC,项目名称:milkman,代码行数:41,代码来源:Profile.cs

示例15: ReadFrom

        public static Profile ReadFrom(DeploymentSettings settings, string profileName)
        {
            var profile = new Profile(profileName);
            var profileFile = settings.ProfileFileNameFor(profileName);

            var fileSystem = new FileSystem();
            if (!fileSystem.FileExists(profileFile))
            {
                var sb = new StringBuilder();
                sb.AppendFormat("Couldn't find the profile '{0}'", profileFile);
                sb.AppendLine();
                sb.AppendLine("Looked in:");
                settings.Directories.Each(d => sb.AppendLine("  {0}".ToFormat(d)));

                throw new Exception(sb.ToString());
            }

            fileSystem.ReadTextFile(profileFile, profile.ReadText);

            return profile;
        }
开发者ID:rsanders1,项目名称:bottles,代码行数:21,代码来源:Profile.cs


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