private void TestPath(string path, int patternEnd, bool isLastPathSegment) { if (!isLastPathSegment) { DoGlob(path, patternEnd, false); return; } if (!NoEscapes) { path = Unescape(path, _stripTwo ? 2 : 0); } else if (_stripTwo) { path = path.Substring(2); } if (_pal.DirectoryExists(path)) { _result.Add(path); } else if (!_dirOnly && _pal.FileExists(path)) { _result.Add(path); } }
private static string GetFullPathAndValidateCase(LanguageContext /*!*/ context, string path, bool isDir) { #if !SILVERLIGHT // check for a match in the case of the filename, unfortunately we can't do this // in Silverlight becauase there's no way to get the original filename. PlatformAdaptationLayer pal = context.DomainManager.Platform; string dir = Path.GetDirectoryName(path); if (!pal.DirectoryExists(dir)) { return(null); } try { string file = Path.GetFileName(path); string[] files = pal.GetFileSystemEntries(dir, file, !isDir, isDir); if (files.Length != 1 || Path.GetFileName(files[0]) != file) { return(null); } return(Path.GetFullPath(files[0])); } catch (IOException) { return(null); } #else return(path); #endif }
internal static bool TryCreate(RubyContext /*!*/ context, string /*!*/ path, out FileSystemInfo result) { PlatformAdaptationLayer pal = context.Platform; result = null; if (pal.FileExists(path)) { result = new FileInfo(path); } else if (pal.DirectoryExists(path)) { result = new DirectoryInfo(path); #if !SILVERLIGHT } else if (path.ToUpperInvariant().Equals(NUL_VALUE)) { result = new DeviceInfo(NUL_VALUE); #endif } else { return(false); } return(true); }
private static string GetFullPathAndValidateCase(LanguageContext /*!*/ context, string path, bool isDir) { // Check for a match in the case of the filename. PlatformAdaptationLayer pal = context.DomainManager.Platform; string dir = pal.GetDirectoryName(path); if (!pal.DirectoryExists(dir)) { return(null); } try { string file = pal.GetFileName(path); string[] files = pal.GetFileSystemEntries(dir, file, !isDir, isDir); if (files.Length != 1 || pal.GetFileName(files[0]) != file) { return(null); } return(pal.GetFullPath(files[0])); } catch (IOException) { return(null); } }
private void TestPath(string path, int patternEnd, bool isLastPathSegment) { if (!isLastPathSegment) { DoGlob(path, patternEnd, false); return; } string pathName = path.Replace('\\', '/'); if (_stripTwo) { pathName = pathName.Substring(2); } if (_pal.DirectoryExists(pathName)) { _result.Add(pathName); } else if (!_dirOnly && _pal.FileExists(pathName)) { _result.Add(pathName); } }
internal static bool TryCreate(RubyContext /*!*/ context, string /*!*/ path, out FileSystemInfo result) { PlatformAdaptationLayer pal = context.DomainManager.Platform; result = null; if (pal.FileExists(path)) { result = new FileInfo(path); } else if (pal.DirectoryExists(path)) { result = new DirectoryInfo(path); } else if (path.ToUpper().Equals(NUL_VALUE)) { result = null; } else { return(false); } return(true); }
private static PythonTuple FindModulePath(CodeContext /*!*/ context, string name, List path) { Debug.Assert(path != null); if (name == null) { throw PythonOps.TypeError("find_module() argument 1 must be string, not None"); } PlatformAdaptationLayer pal = context.LanguageContext.DomainManager.Platform; foreach (object d in path) { string dir = d as string; if (dir == null) { continue; // skip invalid entries } string pathName = Path.Combine(dir, name); if (pal.DirectoryExists(pathName)) { if (pal.FileExists(Path.Combine(pathName, "__init__.py"))) { return(PythonTuple.MakeTuple(null, pathName, PythonTuple.MakeTuple("", "", PackageDirectory))); } } string fileName = pathName + ".py"; if (pal.FileExists(fileName)) { Stream fs = pal.OpenInputFileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite); PythonFile pf = PythonFile.Create(context, fs, fileName, "U"); return(PythonTuple.MakeTuple(pf, fileName, PythonTuple.MakeTuple(".py", "U", PythonSource))); } } throw PythonOps.ImportError("No module named {0}", name); }