libmtp: newfolder.c

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

# newfolder.c

    00001 #include "common.h"
    00002 #include "pathutils.h"
    00003 #include <libgen.h>
    00004
    00005 void newfolder_function(char *);
    00006 void newfolder_command(int,char **);
    00007
    00008 extern LIBMTP_folder_t *folders;
    00009 extern LIBMTP_file_t *files;
    00010 extern LIBMTP_mtpdevice_t *device;
    00011
    00012 void newfolder_command (int argc, char **argv)
    00013 {
    00014   uint32_t newid;
    00015
    00016   if(argc != 3) {
    00017     printf("Usage: newfolder name id\n");
    00018     printf("(id = parent folder or 0 to create the new folder in the root dir)\n");
    00019     return;
    00020   }
    00021
    00022   newid = LIBMTP_Create_Folder(device, argv[1], atol(argv[2]));
    00023   if (newid == 0) {
    00024     printf("Folder creation failed.\n");
    00025   } else {
    00026     printf("New folder created with ID: %d\n", newid);
    00027   }
    00028 }
    00029
    00030 void
    00031 newfolder_function(char * path)
    00032 {
    00033   printf("Creating new folder %s\n",path);
    00034   char * parent = dirname(path);
    00035   char * folder = basename(path);
    00036   int id = parse_path (parent,files,folders);
    00037   int newid = LIBMTP_Create_Folder(device, folder, id);
    00038   if (newid == 0) {
    00039     printf("Folder creation failed.\n");
    00040   } else {
    00041     printf("New folder created with ID: %d\n", newid);
    00042   }
    00043 }
    00044