- @if(0)==(0) echo off
- md test 2>nul
- set ph=%~dp0
- cscript //nologo //E:JScript "%~f0" "%ph%"
- pause&exit
- @end;
- var fso = new ActiveXObject("Scripting.FileSystemObject");
- var re = /^(.*);[^\;]+$/gm;
- var str = '$FORMAT Ticker, Date_YMD, Open, High, Low, Close, Volume' + '\r\n';
- var arr = ['$SKIPLINES 1' , '$SEPARATOR ,' , '$DEBUG 1' , '$BREAKONERR 1', '$AUTOADD 1'];
- String.prototype.strreg = function(filename) {
- return this.replace(re ,
- function(a,b) {
- return filename + '.SS,' + b.replace(/;/g,',') +'\r\n';
- });
- };
- function Files(files){
- var f = fso.GetFolder(files);
- var fc = new Enumerator(f.files);
- for (; !fc.atEnd(); fc.moveNext())
- {
- var file =fc.item();
- var ext=/\.[^\.]+$/.exec(file);
- if (ext == '.txt') {
- var filename = file.name.match(/\d+/);
- var newfile = f + '/test/'+ filename + ext;
- var fs = file.OpenAsTextStream(1, -2);
- var text = str + fs.ReadAll().strreg(filename) + arr.join('\r\n');
- fs.Close();
- var fs = fso.createtextfile(newfile,true);
- fs.Write(text);
- }
- }
- }
-
- Files(WScript.Arguments.Item(0));
复制代码
|