3 * Example program to delete a file off the device.
5 * Copyright (C) 2005-2008 Linus Walleij <triad@df.lth.se>
6 * Copyright (C) 2006 Chris A. Debenham <chris@adebenham.com>
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.
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.
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.
28 #include "pathutils.h"
31 extern LIBMTP_mtpdevice_t *device;
32 extern LIBMTP_folder_t *folders;
33 extern LIBMTP_file_t *files;
35 void delfile_usage(void)
37 printf("Usage: delfile [-n] <fileid/trackid> | -f <filename>\n");
41 delfile_function(char * path)
43 uint32_t id = parse_path (path,files,folders);
46 printf("Deleting %s which has item_id:%d\n",path,id);
48 ret = LIBMTP_Delete_Object(device, id);
50 LIBMTP_Dump_Errorstack(device);
51 LIBMTP_Clear_Errorstack(device);
52 printf("Failed to remove file\n");
59 int delfile_command(int argc, char **argv)
68 if (strncmp(argv[1],"-f",2) == 0) {
69 field_type = FILENAME;
71 } else if (strncmp(argv[1],"-n",2) == 0) {
83 for (i=1;i<argc;i++) {
87 if (field_type == ITEMID) {
88 // Sanity check song ID
89 id = strtoul(argv[i], &endptr, 10);
91 fprintf(stderr, "illegal value %s .. skipping\n", argv[i]);
95 if (strlen(argv[i]) > 0) {
96 id = parse_path (argv[i],files,folders);
102 printf("Deleting %s\n",argv[i]);
103 ret = LIBMTP_Delete_Object(device, id);
106 printf("Failed to delete file:%s\n",argv[i]);
107 LIBMTP_Dump_Errorstack(device);
108 LIBMTP_Clear_Errorstack(device);