libmtp: newfolder.c

libmtp 1.1.21

newfolder.c
#include <stdlib.h>
#include <libgen.h>
#include "common.h"
#include "pathutils.h"
#include "connect.h"
extern LIBMTP_folder_t *folders;
extern LIBMTP_file_t *files;
extern LIBMTP_mtpdevice_t *device;
int newfolder_command (int argc, char **argv)
{
uint32_t newid;
if(argc != 4) {
printf("Usage: newfolder name <parent> <storage>\n");
printf(" parent = parent folder or 0 to create the new folder in the root dir\n");
printf(" storage = storage id or 0 to create the new folder on the primary storage\n");
return 0;
}
newid = LIBMTP_Create_Folder(device, argv[1], atol(argv[2]), atol(argv[3]));
if (newid == 0) {
printf("Folder creation failed.\n");
return 1;
} else {
printf("New folder created with ID: %d\n", newid);
}
return 0;
}
int
newfolder_function(char * path)
{
printf("Creating new folder %s\n",path);
char * parent = dirname(path);
char * folder = basename(path);
int id = parse_path (parent,files,folders);
int newid = LIBMTP_Create_Folder(device, folder, id, 0);
if (newid == 0) {
printf("Folder creation failed.\n");
LIBMTP_Dump_Errorstack(device);
LIBMTP_Clear_Errorstack(device);
return 1;
} else {
printf("New folder created with ID: %d\n", newid);
}
return 0;
}
LIBMTP_Dump_Errorstack
void LIBMTP_Dump_Errorstack(LIBMTP_mtpdevice_t *device)
Definition: libmtp.c:2660
LIBMTP_Clear_Errorstack
void LIBMTP_Clear_Errorstack(LIBMTP_mtpdevice_t *device)
Definition: libmtp.c:2633
LIBMTP_Create_Folder
uint32_t LIBMTP_Create_Folder(LIBMTP_mtpdevice_t *device, char *name, uint32_t parent_id, uint32_t storage_id)
Definition: libmtp.c:7585
LIBMTP_file_struct
Definition: libmtp.h:694
LIBMTP_folder_struct
Definition: libmtp.h:766
LIBMTP_mtpdevice_struct
Definition: libmtp.h:635