Linus Walleij | 9c6ca02 | 2006-04-21 10:24:15 +0000 | [diff] [blame] | 1 | #include "common.h" |
cjdebenh | 4a99f50 | 2006-11-09 22:03:05 +0000 | [diff] [blame^] | 2 | #include <libgen.h> |
Linus Walleij | 9c6ca02 | 2006-04-21 10:24:15 +0000 | [diff] [blame] | 3 | |
cjdebenh | 4a99f50 | 2006-11-09 22:03:05 +0000 | [diff] [blame^] | 4 | void new_folder(char *); |
| 5 | void newfolder(int,char **); |
| 6 | |
| 7 | extern LIBMTP_folder_t *folders; |
| 8 | extern LIBMTP_file_t *files; |
| 9 | extern LIBMTP_mtpdevice_t *device; |
| 10 | |
| 11 | void newfolder (int argc, char **argv) |
Linus Walleij | 9c6ca02 | 2006-04-21 10:24:15 +0000 | [diff] [blame] | 12 | { |
Linus Walleij | c86afbd | 2006-05-04 19:05:24 +0000 | [diff] [blame] | 13 | uint32_t newid; |
Linus Walleij | 9c6ca02 | 2006-04-21 10:24:15 +0000 | [diff] [blame] | 14 | |
| 15 | if(argc != 3) { |
| 16 | printf("Usage: newfolder name id\n"); |
Linus Walleij | c86afbd | 2006-05-04 19:05:24 +0000 | [diff] [blame] | 17 | printf("(id = parent folder or 0 to create the new folder in the root dir)\n"); |
cjdebenh | 4a99f50 | 2006-11-09 22:03:05 +0000 | [diff] [blame^] | 18 | return; |
Linus Walleij | 9c6ca02 | 2006-04-21 10:24:15 +0000 | [diff] [blame] | 19 | } |
| 20 | |
Linus Walleij | c86afbd | 2006-05-04 19:05:24 +0000 | [diff] [blame] | 21 | newid = LIBMTP_Create_Folder(device, argv[1], atol(argv[2])); |
| 22 | if (newid == 0) { |
| 23 | printf("Folder creation failed.\n"); |
| 24 | } else { |
| 25 | printf("New folder created with ID: %d\n", newid); |
| 26 | } |
cjdebenh | 4a99f50 | 2006-11-09 22:03:05 +0000 | [diff] [blame^] | 27 | } |
Linus Walleij | 9c6ca02 | 2006-04-21 10:24:15 +0000 | [diff] [blame] | 28 | |
cjdebenh | 4a99f50 | 2006-11-09 22:03:05 +0000 | [diff] [blame^] | 29 | void |
| 30 | new_folder(char * path) |
| 31 | { |
| 32 | printf("Creating new folder %s\n",path); |
| 33 | char * parent = dirname(path); |
| 34 | char * folder = basename(path); |
| 35 | int id = parse_path (parent,files,folders); |
| 36 | int newid = LIBMTP_Create_Folder(device, folder, id); |
| 37 | if (newid == 0) { |
| 38 | printf("Folder creation failed.\n"); |
| 39 | } else { |
| 40 | printf("New folder created with ID: %d\n", newid); |
| 41 | } |
Linus Walleij | 9c6ca02 | 2006-04-21 10:24:15 +0000 | [diff] [blame] | 42 | } |
| 43 | |