How can I list in a spreadsheet all files id that are located inside a folder ? I have the folder id and the folder contains less than 100 files in total.
function list_all_files_inside_one_folder_without_subfolders(){
var sh = SpreadsheetApp.getActiveSheet();
var folder = DriveApp.getFolderById('0sdfsfd......sfdsdfTg'); // I change the folder ID here
// Logger.log('Folder name: ' + folder.getFiles());
sh.getRange(1,1,1,1).setValues('fileID');
}
Thanks
An addition to the answer: when you do not want to list the folders, only the files in the subfolders, use /A-Dswitch like this: dir ..\myfolder /b /s /A-D /o:gn>list.txt
Command to list all files in a folder as well as sub-folders in windows. 1 Press Windows + R. 2 Press Enter. 3 Type cmd. 4 Press Enter. 5 Type dir -s. 6 Press Enter Share Improve this answer edited Sep 17 '20 at 5:00 answered Jun 21 '17 at 12:52 Zameer Ansari.
Without any arguments, dironly gives information about the files and directories in the current folder, but the OP wants the return to include files in subfolders as well. – Vyren
If you want to set folders property (hidden or unhidden folders), insert any folder processing code in line 65. Download this macro and examples.
This is quite simple if you read the documentation about how to write in a spreadsheet and how to get Drive's content.
Here is an example you can customize if you want :
function list_all_files_inside_one_folder_without_subfolders(){
var sh = SpreadsheetApp.getActiveSheet();
var folder = DriveApp.getFolderById('0B3qSFd3iikE3TERRSHExa29SU3M'); // I change the folder ID here
var list = [];
list.push(['Name','ID','Size']);
var files = folder.getFiles();
while (files.hasNext()){
file = files.next();
var row = []
row.push(file.getName(),file.getId(),file.getSize())
list.push(row);
}
sh.getRange(1,1,list.length,list[0].length).setValues(list);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With