我最初可以访问一个谷歌硬盘文件夹TIF Images,其中包含图片Image01.tif到Image1000.tif。我花了很多时间组织图像,制作快捷方式并将其放入各种快捷方式文件夹中。
由于机构存档政策,我现在失去了对TIF Images的读取权限,但获得了对JPG Images的访问权限,其中包含所有相同图像的较低分辨率.jpg副本。为了避免再次手动组织所有图像,我想使用Google Drive脚本查看每个文件夹的快捷方式,并使用新的.jpg图像重新创建快捷方式。
我想我已经找到了获取.tif图像的所有.jpg版本的第一部分,但实际上我很难创建快捷方式。这是我第一次使用Google脚本或Javascript,所以我确信这段代码是丑陋和错误的。如有任何帮助,将不胜感激。
function myFunction() {
// Get the folder with .jpg's
var jpgFolder = DriveApp.getFolderById("ID of JPG images");
// Get the target new shortcuts folder, which is just the old folder with shortcuts in it
var origFolder = DriveApp.getFolderById("ID of a shortcut folder");
var targetFolder = origFolder;
// Get all the .tif shortcuts out of the original shortcuts
var origFiles = origFolder.getFiles();
while(origFiles.hasNext()){
var origFile = origFiles.next();
var origName = origFile.getName()
// Swap out tif for jpg in the name
const regex = new RegExp("(?:tif)", 'gm')
var str = origName;
const subst = `jpg`;
// The substituted value will be contained in the result variable
var newName = str.replace(regex, subst);
console.log("newName", newName);
// Get the ID for the jpg image
var newFiles = jpgFolder.getFilesByName(newName)
// Probably messing up with the Class Fileiterator here. I need a Class File but not sure how to get that
newFiles.createShortcut(targetFolder)
}
}