delfile.c

00001 #include "common.h"
00002 
00003 static void usage(void)
00004 {
00005   printf("Usage: delfile <fileid/trackid>\n");
00006 }
00007 
00008 int main (int argc, char **argv)
00009 {
00010   LIBMTP_mtpdevice_t *device;
00011   u_int32_t id;
00012   char *endptr;
00013   int ret;
00014 
00015   // We need track ID
00016   if ( argc != 2 ) {
00017     usage();
00018     return 1;
00019   }
00020 
00021   // Sanity check song ID
00022   id = strtoul(argv[1], &endptr, 10);
00023   if ( *endptr != 0 ) {
00024     fprintf(stderr, "illegal value %s\n", argv[1]);
00025     usage();
00026     return 1;
00027   } else if ( ! id ) {
00028     fprintf(stderr, "bad file ID %u\n", id);
00029     usage();
00030     return 1;
00031   }
00032   
00033   LIBMTP_Init();
00034   device = LIBMTP_Get_First_Device();
00035   if (device == NULL) {
00036     printf("No devices.\n");
00037     return 0;
00038   }
00039 
00040   ret = LIBMTP_Delete_Object(device, id);
00041 
00042   if ( ret != 0 ) {
00043     printf("Failed to delete file.\n");
00044     return 1;
00045   }
00046   
00047   LIBMTP_Release_Device(device);
00048   printf("OK.\n");
00049   return 0;
00050 }
00051 

Generated on Tue Sep 12 03:22:54 2006 for libmtp by  doxygen 1.4.7