1/**
2 * \file newfolder.c
3 * Example program to create a folder on the device.
4 *
5 * Copyright (C) 2006-2009 Linus Walleij <triad@df.lth.se>
6 * Copyright (C) 2006 Chris A. Debenham <chris@adebenham.com>
7 *
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
12 *
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16 * Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the
20 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21 * Boston, MA 02111-1307, USA.
22 */
23#include "common.h"
24#include "pathutils.h"
25#include <stdlib.h>
26#include <libgen.h>
27
28void newfolder_function(char *);
29void newfolder_command(int,char **);
30
31extern LIBMTP_folder_t *folders;
32extern LIBMTP_file_t *files;
33extern LIBMTP_mtpdevice_t *device;
34
35void newfolder_command (int argc, char **argv)
36{
37  uint32_t newid;
38
39  if(argc != 4) {
40    printf("Usage: newfolder name <parent> <storage>\n");
41    printf("  parent = parent folder or 0 to create the new folder in the root dir\n");
42    printf("  storage = storage id or 0 to create the new folder on the primary storage\n");
43    return;
44  }
45
46  newid = LIBMTP_Create_Folder(device, argv[1], atol(argv[2]), atol(argv[3]));
47  if (newid == 0) {
48    printf("Folder creation failed.\n");
49  } else {
50    printf("New folder created with ID: %d\n", newid);
51  }
52}
53
54void
55newfolder_function(char * path)
56{
57  printf("Creating new folder %s\n",path);
58  char * parent = dirname(path);
59  char * folder = basename(path);
60  int id = parse_path (parent,files,folders);
61  int newid = LIBMTP_Create_Folder(device, folder, id, 0);
62  if (newid == 0) {
63    printf("Folder creation failed.\n");
64    LIBMTP_Dump_Errorstack(device);
65    LIBMTP_Clear_Errorstack(device);
66  } else {
67    printf("New folder created with ID: %d\n", newid);
68  }
69}
70
71