js复制本地文件(单条和批量)

该博客介绍了如何利用JavaScript调用Cmd.exe命令行来复制本地文件,详细讲解了Cmd.exe的不同参数用法,包括/c、/k、/s、/q等,以及如何在JS中实现文件的单条或批量复制操作。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

/**
 * 单笔拷贝本地影像到远程目录
 */
function moveLocalFileToRemote(){
	try{
		var fso = new ActiveXObject("Scripting.FileSystemObject");
		var videoName = localFilePath.substring(localFilePath.lastIndexOf("/") + 1);
		if(fso.FileExists(localFilePath)){// 如果本地存在当前录制视频文件,则上传;否则不处理
			if(!fso.FolderExists(remoteFilePath)){
				newCreateFolder(remoteFilePath);
			}
			//fso.CopyFile(localFilePath.replace(/\//g,"\\"), remoteFilePath.replace(/\//g,"\\")+ "\\" + videoName); 
			var command = "xcopy " + localFilePath.replace(/\//g,"\\") + " " + remoteFilePath.replace(/\//g,"\\") + "/y";
			var cmd = new ActiveXObject("WScript.Shell");
	    	cmd.run("cmd.exe /c " + command, 0);
	    	cmd = null;
		}
	} catch (error) {
		alert("自动上传面签告警视频失败!");
	}
	localFilePath = "<%=localPath%>";
	remoteFilePath = "<%=savePath%>";
}

/**
 * 批量拷贝本地影像到远程目录
 */
function batchMoveLocalFileToRemote(){
	try{
		var nowDate = new Date().Format("yyyy-MM-dd");
		var localPath = "<%=localPath%>" + "/" + nowDate;
		var fso = new ActiveXObject("Scripting.FileSystemObject");
		var folder = fso.GetFolder(localPath);
		var files = new Enumerator(folder.Files);
		if(!fso.FolderExists(remoteFilePath)){
			newCreateFolder(remoteFilePath);
		}
		
		var command = "echo 正在将本地文件上传到共享文件夹,请勿关闭窗口······";
        for(; !files.atEnd(); files.moveNext()){ 
            var fileName = files.item().Name;
            if(fileName.indexOf("<%=sObjectNo%>") >= 0){
            	if(!fso.FileExists(remoteFilePath + "/" + fileName)){
            		//fso.CopyFile(localFilePath.replace(/\//g,"\\"), remoteFilePath.replace(/\//g,"\\")+ "\\" + videoName); 
            		command += " & xcopy " + localPath.replace(/\//g,"\\") + "\\"+ fileName + " " + remoteFilePath.replace(/\//g,"\\") + "/y";
            	}
            }
        }
        
        var cmd = new ActiveXObject("WScript.Shell");
    	cmd.run("cmd.exe /c " + command, 0);
    	cmd = null;
	} catch (error) {
		alert("自动上传面签告警视频失败!");
	}
	
	localFilePath = "<%=localPath%>";
	remoteFilePath = "<%=savePath%>";
} 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值