Ejemplo n.º 1
0
        /// <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>
        unsafe public string[] GetDirectories(string path)
        {
            if (!IsConnected)
            {
                throw new Exception("Not connected to phone");
            }

            void * hAFCDir   = null;
            string full_path = FullPath(CurrentDirectory, path);
            //full_path = "/private"; // bug test

            int res = MobileDevice.AFCDirectoryOpen(hAFC, 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(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)));
        }
Ejemplo n.º 2
0
        /// <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)));
        }