/// <summary> /// Gets the names of subdirectories in a specified directory. /// </summary> /// <param name="path">The path for which an array of subdirectory names is returned.</param> /// <returns>An array of type <c>String</c> containing the names of subdirectories in <c>path</c>.</returns> public string[] GetDirectories(string path) { if (!IsConnected) { throw new Exception("Not connected to phone"); } IntPtr hAFCDir = IntPtr.Zero; string full_path = FullPath(CurrentDirectory, path); //full_path = "/private"; // bug test int res = MobileDevice.AFCDirectoryOpen(AFCCommsHandle, full_path, ref hAFCDir); if (res != 0) { throw new Exception("Path does not exist: " + res.ToString()); } string buffer = null; ArrayList paths = new ArrayList(); MobileDevice.AFCDirectoryRead(AFCCommsHandle, hAFCDir, ref buffer); while (buffer != null) { if ((buffer != ".") && (buffer != "..") && IsDirectory(FullPath(full_path, buffer))) { paths.Add(buffer); } MobileDevice.AFCDirectoryRead(AFCCommsHandle, hAFCDir, ref buffer); } MobileDevice.AFC.DirectoryClose(AFCCommsHandle, hAFCDir); return((string[])paths.ToArray(typeof(string))); }
public unsafe string[] GetFiles(string path) { if (!this.IsConnected) { throw new Exception("Not connected to phone"); } string str = this.FullPath(this.CurrentDirectory, path); void * dir = null; if (MobileDevice.AFCDirectoryOpen(this.hAFC, str, ref dir) != 0) { throw new Exception("Path does not exist"); } string buffer = null; ArrayList list = new ArrayList(); MobileDevice.AFCDirectoryRead(this.hAFC, dir, ref buffer); while (buffer != null) { if (!this.IsDirectory(this.FullPath(str, buffer))) { list.Add(buffer); } MobileDevice.AFCDirectoryRead(this.hAFC, dir, ref buffer); } MobileDevice.AFCDirectoryClose(this.hAFC, dir); return((string[])list.ToArray(typeof(string))); }
/// <summary> /// Returns the size and type of the specified file or directory. /// </summary> /// <param name="path">The file or directory for which to retrieve information.</param> /// <param name="size">Returns the size of the specified file or directory</param> /// <param name="directory">Returns <c>true</c> if the given path describes a directory, false if it is a file.</param> public void GetFileInfo(string path, out ulong size, out bool directory) { Dictionary <string, string> fi = GetFileInfo(path); size = fi.ContainsKey("st_size") ? System.UInt64.Parse(fi["st_size"]) : 0; bool SLink = false; directory = false; if (fi.ContainsKey("st_ifmt")) { switch (fi["st_ifmt"]) { case "S_IFDIR": directory = true; break; case "S_IFLNK": SLink = true; break; } } if (SLink) { // test for symbolic directory link IntPtr hAFCDir = IntPtr.Zero; if (directory = (MobileDevice.AFCDirectoryOpen(AFCCommsHandle, path, ref hAFCDir) == 0)) { MobileDevice.AFC.DirectoryClose(AFCCommsHandle, hAFCDir); } } }
/// <summary> /// Returns the names of files in a specified directory /// </summary> /// <param name="path">The directory from which to retrieve the files.</param> /// <returns>A <c>String</c> array of file names in the specified directory. Names are relative to the provided directory</returns> unsafe public string[] GetFiles(string path) { if (!IsConnected) { throw new Exception("Not connected to phone"); } string full_path = FullPath(CurrentDirectory, path); void *hAFCDir = null; if (MobileDevice.AFCDirectoryOpen(hAFC, full_path, ref hAFCDir) != 0) { throw new Exception("Path does not exist"); } string buffer = null; ArrayList paths = new ArrayList(); MobileDevice.AFCDirectoryRead(hAFC, hAFCDir, ref buffer); while (buffer != null) { if (!IsDirectory(FullPath(full_path, buffer))) { paths.Add(buffer); } MobileDevice.AFCDirectoryRead(hAFC, hAFCDir, ref buffer); } MobileDevice.AFCDirectoryClose(hAFC, hAFCDir); return((string[])paths.ToArray(typeof(string))); }
/// <summary> /// Gets the names of subdirectories in a specified directory. /// </summary> /// <param name="path">The path for which an array of subdirectory names is returned.</param> /// <returns>An array of type <c>String</c> containing the names of subdirectories in <c>path</c>.</returns> public string[] GetDirectories(string path) { IntPtr hAFCDir; string buffer; ArrayList paths; string full_path; if (!connected) { throw new Exception("Not connected to phone"); } hAFCDir = new IntPtr(); full_path = FullPath(current_directory, path); if (MobileDevice.AFCDirectoryOpen(hAFC, full_path, ref hAFCDir) != 0) { throw new Exception("Path does not exist"); } buffer = null; paths = new ArrayList(); MobileDevice.AFCDirectoryRead(hAFC, hAFCDir, ref buffer); while (buffer != null) { if ((buffer != ".") && (buffer != "..") && IsDirectory(FullPath(full_path, buffer))) { paths.Add(buffer); } MobileDevice.AFCDirectoryRead(hAFC, hAFCDir, ref buffer); } MobileDevice.AFCDirectoryClose(hAFC, hAFCDir); return((string[])paths.ToArray(typeof(string))); }
public string[] GetFiles(string path, bool bIncludeDirs) { if (!IsConnected) { throw new Exception("Not connected to phone"); } string full_path = FullPath(CurrentDirectory, path); IntPtr hAFCDir = IntPtr.Zero; if (MobileDevice.AFCDirectoryOpen(AFCCommsHandle, full_path, ref hAFCDir) != 0) { throw new Exception("Path does not exist"); } string buffer = null; ArrayList paths = new ArrayList(); MobileDevice.AFCDirectoryRead(AFCCommsHandle, hAFCDir, ref buffer); while (buffer != null) { if (!IsDirectory(FullPath(full_path, buffer))) { paths.Add(buffer); } else { if (bIncludeDirs) { paths.Add(buffer + "/"); } } MobileDevice.AFCDirectoryRead(AFCCommsHandle, hAFCDir, ref buffer); } MobileDevice.AFC.DirectoryClose(AFCCommsHandle, hAFCDir); return((string[])paths.ToArray(typeof(string))); }
public unsafe void GetFileInfo(string path, out ulong size, out bool directory) { Dictionary <string, string> fileInfo = this.GetFileInfo(path); size = fileInfo.ContainsKey("st_size") ? ulong.Parse(fileInfo["st_size"]) : ((ulong)0L); bool flag = false; directory = false; if (fileInfo.ContainsKey("st_ifmt")) { string str = fileInfo["st_ifmt"]; if (str != null) { if (!(str == "S_IFDIR")) { if (str == "S_IFLNK") { flag = true; } } else { directory = true; } } } if (flag) { bool flag3; void *dir = null; directory = flag3 = MobileDevice.AFCDirectoryOpen(this.hAFC, path, ref dir) == 0; if (flag3) { MobileDevice.AFCDirectoryClose(this.hAFC, dir); } } }