将Windows版本代码修改为适用于MacOS的版本
以下是将给定的Windows版本代码修改为适用于MacOS的版本:
function WriteFolderName(path, isFolder) {
var effectPath = '/EffectBackup/ListTxt' + path.replace(Folder(path).parent.fsName, '') + '/';
if (!Folder(effectPath).exists) {
Folder(effectPath).create();
}
var pathText = effectPath + (isFolder ? 'folderList' : 'fileList') + '.txt';
var cmd = 'ls -l ' + ''' + path + ''' + (isFolder ? '/ | grep '^d' >' : '/ | grep -v '^d' >') + ''' + pathText + ''';
system.callSystem('bash -c "' + cmd + '"');
var texts = ReadlnToText(pathText);
return texts;
}
function WriteReport(path, poss) {
var reportFile = new File(path);
if (reportFile.exists) {
reportFile.open('w');
reportFile.write(poss);
reportFile.close();
} else {
var RCF_file = new File(reportFile);
RCF_file.open('w');
RCF_file.write(poss);
RCF_file.close();
}
}
function ReadlnToText(path) {
var myFile = new File(path);
var texts = [];
if (myFile.exists) {
var fileOK = myFile.open('r');
if (fileOK) {
while (!myFile.eof) {
var text = myFile.readln();
texts.push(text);
}
}
myFile.close();
}
return texts;
}
function CreateFolder(path) {
var cmd = 'mkdir -p ' + path;
system.callSystem('bash -c "' + cmd + '"');
}
请注意,我进行了一些修改,例如将文件路径分隔符从反斜杠(\)更改为斜杠(/),使用了MacOS上的等效命令(例如,dir改为ls),以及调整了一些文件操作函数(例如,Folder替换了File)。
请确保在使用修改后的代码之前进行测试,并根据您的具体需求进行适当的调整。
原文地址: https://www.cveoy.top/t/topic/YLP 著作权归作者所有。请勿转载和采集!