本帖最后由 aa77dd@163.com 于 2015-6-12 18:53 编辑
回复 27# idctop
经测试的完全代码, 注意包括原来的 jscript 代码也在多处作了修改, mysql 改成你自己的全路径即可了- @if(0)==(0) echo off
- set str="code,name,description,market,suggestion,closing_price,price,exchange rate,price earnings ratio,the main cost,institutional participation"
- dir /b *.txt | cscript -nologo -e:jscript %0 %str%
-
- set "mysql=%ProgramFiles(x86)%\MySQL\MySQL Server 5.6\bin\mysql.exe"
- set "server=127.0.0.1"
- set "port=3306"
- set "username=root"
- set "userpwd=123456"
- set "dbname=gupiao"
- set "tabname=zuoriqgqp"
-
- REM 下行代码为 表 %tabname% 新增两个字段 riqi 和 shijian, 如果字段还没有建立, 就运行一次, 之后就不要再运行了.
- rem "%mysql%" -h%server% -P%port% -u%username% -p%userpwd% -D%dbname% -e "ALTER TABLE `%tabname%` ADD COLUMN (`riqi` DATE, `shijian` TIME);"
-
- for /f "delims=" %%a in ('dir /b *.txt') do (
- echo %%a
- "%mysql%" -h%server% -P%port% -u%username% -p%userpwd% -D%dbname% -e "LOAD DATA LOCAL INFILE '%%a' INTO TABLE `%tabname%` FIELDS TERMINATED BY ',' LINES TERMINATED BY '\r\n' IGNORE 1 LINES (`riqi`, `shijian`, `code`, `name`, `description`, `market`, `suggestion`, `closing_price`, `price`, `exchange rate`, `price earnings ratio`, `the main cost`, `institutional participation`);"
- )
-
- if not exist done md done
- move /y *.txt done\
-
- pause & exit
- @end
- var fso = new ActiveXObject("Scripting.FileSystemObject");
- var s = WScript.Arguments.Item(0);
- var re = new RegExp("^" + s, "i");
- var reg = /.*\[标签:内容\].*/g;
- var fso = new ActiveXObject("Scripting.FileSystemObject");
- var now = new Date();
- var s_date = now.getFullYear() + '-' + (now.getMonth() + 1) + '-' + now.getDate();
- var s_time = now.getHours() + ':' + now.getMinutes() + ':' + now.getSeconds();
-
- var time_source = 'file_name'; // 值为 'file_name' : 从数据文件名获取时间; 否则, 获取系统当前时间;
-
- while (!WScript.StdIn.AtEndOfStream){
- var filename = WScript.StdIn.Readline();
- if (time_source == 'file_name') {
- var s_dt = filename.replace(/股票数据|\.txt/gi, '').split(' ');
- s_date = s_dt[0];
- s_time = s_dt[1].replace(/-/g, ':');
- }
- var text = adoLoadText(filename, 'UTF-8').replace(/\r?\n/ig,'');
- while (!(re.test(text))){
- text = s + "\r\n" + s_date + ',' + s_time + ',' + text.replace(/&sbquo/ig,',').replace(/","/ig,'\r\n' + s_date + ',' + s_time + ',').replace(reg,'');
- TextToFile(text, filename);
- }
- }
- function adoLoadText(filename, charset) {
- var fs, text;
- fs = new ActiveXObject("ADODB.Stream");
- fs.type = 2;
- fs.charset = charset;
- fs.open();
- fs.loadFromFile(filename);
- text = fs.readText(-1);
- fs.close();
- return text;
- }
- function TextToFile(text, filename) {
- var fs = new ActiveXObject("Adodb.Stream");
- fs.Charset = 'UTF-8';
- fs.Open();
- fs.WriteText(text);
- fs.SaveToFile(filename, 2);
- fs.Close();
- }
复制代码
|