/**
* JS copy指定文件到指定路径下
* @param filepath 要copy的文件路径
* @param path 把文件copy到这儿
*/
function jsCopyFileToPath(filepath,path){
var fso = new ActiveXObject("Scripting.FileSystemObject");
//取得目录对象
var f = fso.GetFile(filepath);
fso.CopyFile(f, path+f.Name);
return true;
}
/**
* JS copy指定文件夹下所有文件到指定路径下
* @param filepath 要copy的文件夹路径
* @param path 把文件copy到这儿
* @param ffix 要copy的文件的后缀,如不设置则全部copy
*/
function jsCopyFilesToPath(filepath,path,ffix){
var fso = new ActiveXObject("Scripting.FileSystemObject");
//取得目录对象
var f = fso.GetFolder(filepath);
var ff = new Enumerator(f.Files); //该目录下所有的文件集合
var filefix = "";
for(;!ff.atEnd();ff.moveNext()){
//取得文件后缀
filefix = fso.GetExtensionName(ff.item().Path);
//如果文件后缀是txt,则copy文件
if(ffix==null || ffix=='' || ffix==filefix){
fso.CopyFile(ff.item(), path);
}
}
return true;
}
var fso = new ActiveXObject("Scripting.FileSystemObject");
var folder = fso.GetFolder("C:\\libinghua");
alert("文件数:" + folder.Files.Count);
var filesEnum = new Enumerator(folder.Files);
for (; !filesEnum.atEnd(); filesEnum.moveNext())
{
document.write(filesEnum.item().Name + "");
}
window.onload=jsCopyFilesToPath("C:\\libinghua","D:\\log\\","");
var fso = new ActiveXObject("Scripting.FileSystemObject");
var newpath = fso.CopyFile("d:\\log\\2011-5-1.txt", "c:\\libinghua");
fso = new ActiveXObject("Scripting.FileSystemObject"); fso.CopyFolder ("C:\\test\\*","D:\\log\\");
</script>
</head>
<body>
</body>
</html>