删除或删除云端硬盘中的特定文件 [英] Delete or Trash specific file in Drive

查看:144
本文介绍了删除或删除云端硬盘中的特定文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个脚本,该脚本每天凌晨5点运行,可以将特定文件(data.xls)移到回收站.但是,由于DocsList已淘汰,该脚本不再起作用,并且我无法对其进行更新.

I had a script that ran every day at 5 am, that would move a specific file (data.xls) to the trash. However, since DocsList has been retired, the script no longer functions, and I'm having trouble updating it.

我已经在这里看到了几个delete/setTrashed脚本,但是它们似乎都可以对一系列文件起作用,我只希望删除一个特定文件.

I've seen a couple of delete/setTrashed scripts posted here, but they all seem to function for an array of files, and i only want one specific file deleted.

我不是编码员,我会自己教自己大部分的小额知识,所以我需要尽可能简单(抱歉)

I'm not a coder, and self-taught myself most of the small amount i have, so i need it as simple as possible (sorry.)

我们非常感谢您提供的所有帮助或指导.谢谢.

Any and all help or guidance is very appreciated. Thank you.

function myFunction() {
var files = DriveApp.getFilesByName('data');
 while (files.hasNext()) {
   var file = files.next();
   ID = file.getId(file)
   Drive.Files.remove(ID);
 }
}

推荐答案

我在这里看到了几个delete/setTrashed脚本,但是它们 似乎所有功能都适用于一系列文件,而我只想要一个 特定文件已删除.

I've seen a couple of delete/setTrashed scripts posted here, but they all seem to function for an array of files, and i only want one specific file deleted.

简单地说,要删除单个文件,请删除列表中的第一项,即所谓的数组和Google所说的文件迭代器.

Simply put, to delete a single file you delete the first item in the list, what you are calling an array and what Google calls a file iterator.

按名称检索文件将返回一个列表(迭代器),即使该名称只有一个文件也是如此,因此您必须将单个项目视为迭代器中的第一项,并将该第一项设置为垃圾箱

Retrieving a file by name is going to return a list(iterator), even if it has only one file by that name, so you must treat the single item as the first item in the iterator and set that first item to trash.

function myFunction() {
var files = DriveApp.getFilesByName('data');
 while (files.hasNext()) {
   files.next().setTrashed(true);
   }
  }

如果您知道该名称只有一个文件,则可以执行以下操作:

if you know that there is one and only one file by that name you could do something as simple as:

function myFunction() {
    DriveApp.getFilesByName('data').next().setTrashed(true);
       }

这篇关于删除或删除云端硬盘中的特定文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆