我希望下面的GAS删除给定文件夹中具有相同名称的文件。另一个循环中的循环应将所有文件与所有文件进行比较,但不是。
由于该文件夹中有5个文件,该脚本应进行5x5比较,但仅进行5x5比较。我的错在哪里?
代码:
function setTrashedDuplicatedFiles(){
var folder = DriveApp.getFolderById("1FfbNvPQpg6Ilx-5VLuSIePvpl-FxewFl");
var files = folder.getFiles();
var files_ = folder.getFiles();
while (files.hasNext())
{
var file = files.next()
while (files_.hasNext())
{
var file_ = files_.next()
Logger.log("file: " + file + " = " + "file_: " + file_)
Logger.log("file.getId(): " + file.getId() + " = " + "file_.getId(): " + file_.getId())
if((file === file_) && (file.getId() != file_.getId()))
{
file.setTrashed(true)
}
}
}
}
当前输出:
file: File1.pdf = file_: File1.pdf
file.getId(): 1yyFlRAGISjKstVxPRu8Eqi4iCIYJGDZA = file_.getId(): 1yyFlRAGISjKstVxPRu8Eqi4iCIYJGDZA
file: File1.pdf = file_: File2.pdf
file.getId(): 1yyFlRAGISjKstVxPRu8Eqi4iCIYJGDZA = file_.getId(): 1LY68d1aP9DLe5LqkzZyCJVdQIAm9XzzY
file: File1.pdf = file_: File2.pdf
file.getId(): 1yyFlRAGISjKstVxPRu8Eqi4iCIYJGDZA = file_.getId(): 19tKdBNt5bzxAOfcO1n14a_DbjWLb-LN-
file: File1.pdf = file_: File1.pdf
file.getId(): 1yyFlRAGISjKstVxPRu8Eqi4iCIYJGDZA = file_.getId(): 1Quwyi6WIP0dt3qgV4S5XJof1wMu9mRP1
file: File1.pdf = file_: File1.pdf
file.getId(): 1yyFlRAGISjKstVxPRu8Eqi4iCIYJGDZA = file_.getId(): 1fjMu1NEJu9ZI3aFhYpFyLkw_o79KiTQa