libmtp: newfolder.c

- Main Page
- Modules
- Data Structures
- Files
- Directories
- Examples

# newfolder.c

    00001
    00023 #include "common.h"
    00024 #include "pathutils.h"
    00025 #include <libgen.h>
    00026
    00027 void newfolder_function(char *);
    00028 void newfolder_command(int,char **);
    00029
    00030 extern LIBMTP_folder_t *folders;
    00031 extern LIBMTP_file_t *files;
    00032 extern LIBMTP_mtpdevice_t *device;
    00033
    00034 void newfolder_command (int argc, char **argv)
    00035 {
    00036   uint32_t newid;
    00037
    00038   if(argc != 3) {
    00039     printf("Usage: newfolder name id\n");
    00040     printf("(id = parent folder or 0 to create the new folder in the root dir)\n");
    00041     return;
    00042   }
    00043
    00044   newid = LIBMTP_Create_Folder(device, argv[1], atol(argv[2]));
    00045   if (newid == 0) {
    00046     printf("Folder creation failed.\n");
    00047   } else {
    00048     printf("New folder created with ID: %d\n", newid);
    00049   }
    00050 }
    00051
    00052 void
    00053 newfolder_function(char * path)
    00054 {
    00055   printf("Creating new folder %s\n",path);
    00056   char * parent = dirname(path);
    00057   char * folder = basename(path);
    00058   int id = parse_path (parent,files,folders);
    00059   int newid = LIBMTP_Create_Folder(device, folder, id);
    00060   if (newid == 0) {
    00061     printf("Folder creation failed.\n");
    00062     LIBMTP_Dump_Errorstack(device);
    00063     LIBMTP_Clear_Errorstack(device);
    00064   } else {
    00065     printf("New folder created with ID: %d\n", newid);
    00066   }
    00067 }
    00068