/// <summary> /// Merges the path with the current working directory /// to get a canonicalized absolute pathname representing the same path /// (local files only). If the provided <paramref name="path"/> /// is absolute (rooted local path or an URL) it is returned unchanged. /// </summary> /// <param name="ctx">Runtime context.</param> /// <param name="path">An absolute or relative path to a directory or an URL.</param> /// <returns>Canonicalized absolute path in case of a local directory or the original /// <paramref name="path"/> in case of an URL.</returns> internal static string AbsolutePath(Context ctx, string path) { // Don't combine remote file paths with CWD. try { if (IsRemoteFile(path)) { return(path); } // Remove the file:// schema if any. path = GetFilename(path); // Combine the path and simplify it. string combinedPath = Path.Combine(PhpDirectory.getcwd(ctx), path); // Note: GetFullPath handles "C:" incorrectly if (combinedPath[combinedPath.Length - 1] == ':') { combinedPath += PathUtils.DirectorySeparator; } return(Path.GetFullPath(combinedPath)); } catch (System.Exception) { PhpException.Throw(PhpError.Notice, string.Format(Resources.LibResources.invalid_path, FileSystemUtils.StripPassword(path))); return(null); } }
/// <summary> /// Restart the directory listing. /// </summary> public virtual void rewind(PhpResource handle = null) { var res = handle ?? this.handle; if (res != null) { PhpDirectory.rewinddir(res); } else { PhpException.InvalidImplicitCast(nameof(handle), PhpResource.PhpTypeName, "rewind"); } }
/// <summary> /// Finish the directory listing. /// </summary> public virtual void close(PhpResource handle = null) { var res = handle ?? this.handle; if (res != null) { PhpDirectory.closedir(res); } else { PhpException.InvalidImplicitCast(nameof(handle), PhpResource.PhpTypeName, nameof(close)); } }
public string read(PhpResource handle = null) { var res = handle ?? this.handle; if (res != null) { return(PhpDirectory.readdir(res)); } else { PhpException.InvalidImplicitCast(nameof(handle), PhpResource.PhpTypeName, "read"); return(null); } }
/// <summary> /// Start listing of a directory (intended to be used from C#). /// </summary> /// <param name="ctx">Runtime context.</param> /// <param name="directory">The path to the directory.</param> public Directory(Context ctx, string directory) { this.path = directory; this.handle = PhpDirectory.opendir(ctx, directory); }
/// <summary> /// Start listing of a directory (intended to be used from C#). /// </summary> /// <param name="ctx">Runtime context.</param> /// <param name="directory">The path to the directory.</param> public Directory(Context ctx, string directory) { this.path = (PhpValue)directory; this.handle = PhpValue.FromClass(PhpDirectory.opendir(ctx, directory)); }