- 0<1/*,:
- @echo off
- REM 功能:将目录下的文件按指定数量组合并拷贝到目标目录
- REM 设置文件搜索目录路径
- set srcdir="e:\test\new folder"
- REM 设置输出文件所在目录路径
- set dstdir="e:\test\new folder\new"
- REM 设置文件组合的数量
- set count=7
- cscript -nologo -e:jscript %0 /srcdir:%srcdir% /dstdir:%dstdir% /count:%count%
- pause
- exit /b
- */
- ;
- var fso = new ActiveXObject('Scripting.FileSystemObject');
- var srcdir = WScript.Arguments.Named('srcdir');
- var dstdir = WScript.Arguments.Named('dstdir');
- var count = parseInt(WScript.Arguments.Named('count'));
- if (isNaN(count)) {
- showError('count 不是数字');
- WScript.Quit(1);
- }
- try {
- var folder = fso.getFolder(srcdir);
- } catch (e) {
- showError(srcdir + ' 不存在');
- WScript.Quit(2);
- }
-
- if (!fso.FolderExists(dstdir)) {
- try {
- fso.CreateFolder(dstdir);
- } catch (e) {
- showError('无法创建目录:' + dstdir);
- WScript.Quit(3);
- }
- }
-
- for (var arrFiles = [], colFiles = new Enumerator(folder.Files); !colFiles.atEnd(); colFiles.moveNext()) {
- arrFiles.push(colFiles.item());
- }
- for (var arrComb = combination(arrFiles, count), i = 0, l = arrComb.length; i < l; i++) {
- try {
- var currdir = fso.BuildPath(dstdir, String(i + 1));
- if (!fso.FolderExists(currdir)) {
- fso.CreateFolder(currdir);
- }
- var arrCombMember = arrComb[i];
- for (var j = arrCombMember.length - 1; j >= 0; j--) {
- arrCombMember[j].Copy(currdir + '\\', true);
- WScript.Echo(arrCombMember[j].Path + ' >> ' + currdir);
- }
- } catch (e) {
- WScript.Echo('Error:' + currdir);
- }
- }
-
- function combination(arr, n) {
- var arrA = [];
- if (0 === n) return [
- []
- ];
- if (n >= arr.length) {
- arrA.push(arr);
- return arrA;
- }
- for (var i = 0, k = arr.length - n + 1; i < k; i++) {
- for (var j = 0, t = combination(arr.slice(i + 1), n - 1), l = t.length; j < l; j++) {
- t[j].unshift(arr[i]);
- arrA.push(t[j]);
- }
- }
- return arrA;
- }
-
- function showError(err, source) {
- WScript.Echo('[object Error]' === Object.prototype.toString.call(err) ? [
- err.name,
- 'source: ' + (undefined === source ? '' : source),
- 'number: ' + (err.number >>> 0).toString(16),
- 'equipment: ' + (err.number >> 16 & 0x1FFF),
- 'code: ' + (err.number & 0xFFFF),
- 'Information: ' + err.message
- ].join('\n') :
- err);
- }
复制代码
|