FileExists() public method

Returns true iff a file with the given name exists.
public FileExists ( string name ) : bool
name string
return bool
示例#1
0
        public bool TryLoad(string path, IndexLoadOptions options)
        {
            try
            {
                _directory = FSDirectory.Open(path);
                _reader = IndexReader.Open(_directory, options.ReadOnly);

                if (options.ForceUnlock && _directory.FileExists(IndexWriter.WRITE_LOCK_NAME))
                {
                    _directory.ClearLock(IndexWriter.WRITE_LOCK_NAME);
                }

                var fields = _reader.GetFieldNames(IndexReader.FieldOption.ALL);
                _numFields = fields.Count;

                CountTerms();

                foreach (var file in _directory.ListAll())
                {
                    try
                    {
                        string fpath = Path.Combine(_directory.Directory.ToString(), file);

                        if (_lastModified == null)
                            _lastModified = File.GetLastWriteTimeUtc(fpath);
                        else
                        {
                            var mod = File.GetLastWriteTimeUtc(fpath);
                            if (mod > _lastModified.Value)
                                _lastModified = mod;
                        }
                    }
                    catch
                    {
                        // ignore
                    }
                }

                _loaded = true;
                return true;
            }
            catch
            {
                _directory = null;
                _reader = null;
                _numFields = 0;
                _numTerms = 0;
                _loaded = false;
                _lastModified = null;
                return false;
            }
        }
示例#2
0
 public override bool FileExists(System.String name, IState state)
 {
     return(fsDir.FileExists(name, null));
 }
示例#3
0
 private void EnsureIndexVersionMatches(FSDirectory directory)
 {
     if (directory.FileExists(indexVersionFilename) == false)
         throw new InvalidOperationException("Could not find " + indexVersionFilename + " for '" + this.name + "', resetting index");
     
     using (var indexInput = directory.OpenInput(indexVersionFilename))
     {
         var versionToCheck = IndexVersion;
         var versionFromDisk = indexInput.ReadString();
         if (versionFromDisk != versionToCheck)
             throw new InvalidOperationException("Index for " + this.name + " is of version " + versionFromDisk +
                                                 " which is not compatible with " + versionToCheck + ", resetting index");
     }
 }