我想将文件从一个目录移动到另一个目录。
我获取了所有文件以及每个文件的大小,但是当我通过ajax验证文件是否存在时,总是会出现错误结果。我没有太多使用ajax,但是如果我得到了我需要的所有信息,为什么我无法移动文件?
这是我使用的代码:
moveErrorFiles('C:/Users/romama/Desktop/HMI Versions/V 0.5/web/css');
function moveErrorFiles(fileDir){
var fileSysObj, file, folder, fileCounter, currentFile;
fileSysObj = new ActiveXObject("Scripting.FileSystemObject");
folder = fileSysObj.GetFolder(fileDir);
fileCounter = new Enumerator(folder.files);
for (; !fileCounter.atEnd(); fileCounter.moveNext()) {
currentFile = fileCounter.item();
file = fileSysObj.GetFile(currentFile)
checkFileExist(file, file.Size);
}
}
function checkFileExist(fileToMove, size) {
$.ajax({
url: fileToMove,
type: 'HEAD',
contentType: 'image/png',
dataType: 'text',
cache: false,
error: function() {
console.log(fileToMove + "\nthis file doesn't exist... Size = " + size);
},
success: function() {
console.log(fileToMove + '\nthis file exists... Size = ' + size);
}
});
}
这是 IE 控制台中的输出:
C:\Users\romama\Desktop\HMI Versions\V 0.5\web\css\style.css
this file doesn't exist... Size = 13823
C:\Users\romama\Desktop\HMI Versions\V 0.5\web\css\styleSmall.css
this file doesn't exist... Size = 13634
最佳答案
这违反了浏览器的规则。
您可以读取元数据,但无法修改/删除文件。
正如里奇所说,这将是一个安全漏洞。
想象一下您访问网站 www.goofup.com,只是为了知道该网站删除了您的操作系统。
你肯定不会想要这样的。
关于javascript - Ajax 文件不存在,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50605815/