Code Sync up from tizen_2.4
[platform/upstream/libmtp.git] / examples / newfolder.c
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 <stdlib.h>
24 #include <libgen.h>
25
26 #include "common.h"
27 #include "pathutils.h"
28 #include "connect.h"
29
30 extern LIBMTP_folder_t *folders;
31 extern LIBMTP_file_t *files;
32 extern LIBMTP_mtpdevice_t *device;
33
34 int newfolder_command (int argc, char **argv)
35 {
36   uint32_t newid;
37
38   if(argc != 4) {
39     printf("Usage: newfolder name <parent> <storage>\n");
40     printf("  parent = parent folder or 0 to create the new folder in the root dir\n");
41     printf("  storage = storage id or 0 to create the new folder on the primary storage\n");
42     return 0;
43   }
44
45   newid = LIBMTP_Create_Folder(device, argv[1], atol(argv[2]), atol(argv[3]));
46   if (newid == 0) {
47     printf("Folder creation failed.\n");
48     return 1;
49   } else {
50     printf("New folder created with ID: %d\n", newid);
51   }
52   return 0;
53 }
54
55 int
56 newfolder_function(char * path)
57 {
58   printf("Creating new folder %s\n",path);
59   char * parent = dirname(path);
60   char * folder = basename(path);
61   int id = parse_path (parent,files,folders);
62   int newid = LIBMTP_Create_Folder(device, folder, id, 0);
63   if (newid == 0) {
64     printf("Folder creation failed.\n");
65     LIBMTP_Dump_Errorstack(device);
66     LIBMTP_Clear_Errorstack(device);
67     return 1;
68   } else {
69     printf("New folder created with ID: %d\n", newid);
70   }
71   return 0;
72 }
73