// https://api.slack.com/methods/files.list

const argv = require('yargs')
  .string('token')
  .number('before')
  .boolean('nodelete')
  .argv;

const requestPromise = require('request-promise');
const oneDayMSec = 86400000;
const getFiles = function (uri) {
  return requestPromise(options);
};

const fileListAPIoptions = {
  method: 'POST',
  uri: 'https://slack.com/api/files.list',
  form: {
    token: argv.token,
    ts_to: Math.floor((new Date().getTime() - oneDayMSec * argv.before || 30) / 1000)
  },
  json: true
};

requestPromise(fileListAPIoptions)
  .then(function (json) {
    if (argv.nodelete) return;

    return Promise.all(json.files.map(function (item) {
      const fileDeleteAPIoptions = {
        method: 'POST',
        uri: 'https://slack.com/api/files.delete',
        form: {
          token: argv.token,
          id: item.id
        },
        json: true
      };

      return requestPromise(fileDeleteAPIoptions)
        .then(function (json) {
        })
        .catch(function (err) {
          console.error(err);
        })

    }));
  })
  .catch(function (err) {
    console.error(err);
  });

@@ -614,16 +614,52 @@
  return;
+%0A    console.log('delete files...');
 %0A%0A    re
@@ -704,24 +704,67 @@
 on (item) %7B%0A
+      console.log(%60File ID: $%7Bitem.id%7D%60);%0A%0A
       const 
@@ -918,18 +918,20 @@
         
-id
+file
 : item.i
@@ -1050,24 +1050,53 @@
 on (json) %7B%0A
+          console.log(json);%0A
         %7D)%0A 
@@ -1156,16 +1156,16 @@
 r(err);%0A
+
         
@@ -1167,17 +1167,16 @@
      %7D)%0A
-%0A
     %7D));

add log