Logo Search packages:      
Sourcecode: libgphoto2 version File versions

int gp_filesystem_remove_dir ( CameraFilesystem fs,
const char *  folder,
const char *  name,
GPContext context 
)

Remove a subfolder from within a folder.

Parameters:
fs a CameraFilesystem
folder the folder in which the directory should be created
name the name of the directory to be created
context a GPContext
Removes a directory called name from the given folder.

Returns:
a gphoto2 error code

Definition at line 1202 of file gphoto2-filesys.c.

References CHECK_NULL, _CameraFilesystem::folder_data, GP_ERROR_DIRECTORY_EXISTS, GP_ERROR_FILE_EXISTS, GP_ERROR_NOT_SUPPORTED, gp_filesystem_list_files(), gp_filesystem_list_folders(), gp_list_count(), gp_list_free(), gp_list_new(), and _CameraFilesystem::remove_dir_func.

Referenced by gp_camera_folder_remove_dir().

{
      int x;
      char path[2048];
      CameraList *list;

      CHECK_NULL (fs && folder && name);
      CC (context);
      CA (folder, context);


      if (!fs->remove_dir_func)
            return (GP_ERROR_NOT_SUPPORTED);

      CR (gp_list_new (&list));
      /*
       * Make sure there are neither files nor folders in the folder
       * that is to be removed.
       */
      strncpy (path, folder, sizeof (path));
      if (path[strlen (path) - 1] != '/')
            strncat (path, "/", sizeof (path) - strlen (path) - 1);
      strncat (path, name, sizeof (path) - strlen (path) - 1);
      CL (gp_filesystem_list_folders (fs, path, list, context), list);
      if (gp_list_count (list)) {
            gp_context_error (context, _("There are still subfolders in "
                  "folder '%s' that you are trying to remove."), path);
            gp_list_free (list);
            return (GP_ERROR_DIRECTORY_EXISTS);
      }
      CL (gp_filesystem_list_files (fs, path, list, context), list);
      if (gp_list_count (list)) {
            gp_context_error (context, _("There are still files in "
                  "folder '%s' that you are trying to remove."), path);
            gp_list_free(list);
            return (GP_ERROR_FILE_EXISTS);
      }
      gp_list_free(list);

      /* Search the folder */
      CR (x = gp_filesystem_folder_number (fs, path, context));

      /* Remove the directory */
      CR (fs->remove_dir_func (fs, folder, name, fs->folder_data, context));
      CR (delete_folder (fs, x));

      return (GP_OK);
}


Generated by  Doxygen 1.6.0   Back to index