求教:下列js代码,第1行 第2行 子文件夹 000001~100000 的路径变量如何表述?- var path1 = 'C:\\文件夹1\\000001~100000\\'; //源文件路径
- var path2 = 'C:\\文件夹2\\000001~100000\\'; //目标文件路径
-
- var getText = function(file){
- var ado = new ActiveXObject('Adodb.Stream');
- ado.Type = 2;
- ado.CharSet = 'UTF-8';
- ado.Open();
- ado.LoadFromFile(file);
- var text = ado.ReadText(-1);
- ado.Close();
- return text;
- }
-
- var saveFile = function(file){
- var ado = new ActiveXObject('Adodb.Stream');
- ado.Type = 2;
- ado.CharSet = 'UTF-8';
- ado.Open();
- ado.WriteText(out.join('\r\n'));
- ado.SaveToFile(file, 2);
- ado.Close();
- }
-
- var fso = new ActiveXObject('Scripting.FileSystemObject');
- if( !fso.FolderExists(path2) ) fso.CreateFolder(path2);
-
- var e = new Enumerator( fso.GetFolder(path1).Files );
- var reg = /^((?:(?!->)\S)+)=(\S+)(?=\r\n|$)/mg;
-
- for(; !e.atEnd(); e.moveNext()){
- if( !/\.txt$/i.test(e.item().Name) ) continue;
- var map = {};
- var out = [];
- var str = getText( e.item().Path );
- while( arr = reg.exec(str) ){
- var key = arr[1].toLowerCase();
- map[key] = map.hasOwnProperty(key) ? map[key] + ' ' + arr[2] : arr[0];
- }
- for( var key in map ) out.push(map[key]);
- saveFile( path2 + e.item().Name );
- }
复制代码
|