OLD | NEW |
1 /** | 1 /** |
2 * \file filetree.c | 2 * \file filetree.c |
3 * List all files and folders of all storages recursively | 3 * List all files and folders of all storages recursively |
4 * | 4 * |
5 * Copyright (C) 2011 Linus Walleij <triad@df.lth.se> | 5 * Copyright (C) 2011 Linus Walleij <triad@df.lth.se> |
6 * | 6 * |
7 * This library is free software; you can redistribute it and/or | 7 * This library is free software; you can redistribute it and/or |
8 * modify it under the terms of the GNU Lesser General Public | 8 * modify it under the terms of the GNU Lesser General Public |
9 * License as published by the Free Software Foundation; either | 9 * License as published by the Free Software Foundation; either |
10 * version 2 of the License, or (at your option) any later version. | 10 * version 2 of the License, or (at your option) any later version. |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
42 LIBMTP_file_t *file; | 42 LIBMTP_file_t *file; |
43 | 43 |
44 files = LIBMTP_Get_Files_And_Folders(device, | 44 files = LIBMTP_Get_Files_And_Folders(device, |
45 storage->id, | 45 storage->id, |
46 leaf); | 46 leaf); |
47 if (files == NULL) { | 47 if (files == NULL) { |
48 return; | 48 return; |
49 } | 49 } |
50 | 50 |
51 /* Iterate over the filelisting */ | 51 /* Iterate over the filelisting */ |
52 for (file = files; file != NULL; file = file->next) { | 52 file = files; |
| 53 while (file != NULL) { |
53 int i; | 54 int i; |
| 55 LIBMTP_file_t *oldfile; |
54 | 56 |
55 /* Indent */ | 57 /* Indent */ |
56 for (i = 0; i < depth; i++) { | 58 for (i = 0; i < depth; i++) { |
57 printf(" "); | 59 printf(" "); |
58 } | 60 } |
59 printf("%u %s\n", file->item_id, file->filename); | 61 printf("%u %s\n", file->item_id, file->filename); |
60 if (file->filetype == LIBMTP_FILETYPE_FOLDER) { | 62 if (file->filetype == LIBMTP_FILETYPE_FOLDER) { |
61 recursive_file_tree(device, storage, file->item_id, depth+2); | 63 recursive_file_tree(device, storage, file->item_id, depth+2); |
62 } | 64 } |
| 65 |
| 66 oldfile = file; |
| 67 file = file->next; |
| 68 LIBMTP_destroy_file_t(oldfile); |
63 } | 69 } |
64 } | 70 } |
65 | 71 |
66 int main (int argc, char **argv) | 72 int main (int argc, char **argv) |
67 { | 73 { |
68 LIBMTP_raw_device_t * rawdevices; | 74 LIBMTP_raw_device_t * rawdevices; |
69 int numrawdevices; | 75 int numrawdevices; |
70 LIBMTP_error_number_t err; | 76 LIBMTP_error_number_t err; |
71 int i; | 77 int i; |
72 | 78 |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
147 bailout: | 153 bailout: |
148 LIBMTP_Release_Device(device); | 154 LIBMTP_Release_Device(device); |
149 } /* End For Loop */ | 155 } /* End For Loop */ |
150 | 156 |
151 free(rawdevices); | 157 free(rawdevices); |
152 | 158 |
153 printf("OK.\n"); | 159 printf("OK.\n"); |
154 | 160 |
155 return 0; | 161 return 0; |
156 } | 162 } |
OLD | NEW |