Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

List all files id inside a folder (no subfolders)

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

like image 256
miodf Avatar asked Aug 18 '14 09:08

miodf


People also ask

How to list only the files in the subfolders?

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

How to list all files in a folder in Windows?

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.

Does dironly include files in sub folders?

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

How to set folders property (hidden or unhidden)?

If you want to set folders property (hidden or unhidden folders), insert any folder processing code in line 65. Download this macro and examples.


1 Answers

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);
}
like image 102
Serge insas Avatar answered Oct 16 '22 17:10

Serge insas