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> /// 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))); }
/// <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))); }