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-08-05 08:00
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » Please clarify the specific requirements for the VBS code. For now, here is a simple example of a VBS script to traverse drives and find the 11.exe file (this is a basic framework, you can adjust it according to actual needs): ```vbscript Set objFSO = CreateObject("Scripting.FileSystemObject") Set colDrives = objFSO.Drives For Each objDrive in colDrives If objDrive.DriveType = 3 Then 'Only process fixed drives strDrive = objDrive.Path strSearch = strDrive & "11.exe" If objFSO.FileExists(strSearch) Then WScript.Echo "Found 11.exe at: " & strSearch End If End If Next ``` Please note that this is a simple search logic. It just traverses fixed drives and checks for the existence of 11.exe directly in the root directory. If you need more complex search functions (like searching recursively in subdirectories), it needs to be further extended. View 2,611 Replies 28
Original Poster Posted 2007-02-11 06:18 ·  中国 吉林 四平 联通
高级用户
★★★
Credits 859
Posts 413
Joined 2006-08-14 21:55
19-year member
UID 60532
Status Offline
Please provide the specific Chinese content that needs to be translated. Currently, the text you provided is in Chinese but not fully clear. Please clarify the complete text that needs translation.
Floor 2 Posted 2007-02-11 11:54 ·  中国 吉林 四平 联通
高级用户
★★★
Credits 859
Posts 413
Joined 2006-08-14 21:55
19-year member
UID 60532
Status Offline
Floor 3 Posted 2007-02-11 12:36 ·  中国 陕西 西安 电信
铂金会员
★★★★
Credits 5,212
Posts 2,478
Joined 2007-02-08 23:39
19-year member
UID 79003
Gender Male
Status Offline
Suggest using dir /s /b partition:\*.exe

Then have a VBS read the text file containing all the file paths. Check if the last 5 characters of each line are 11.exe

[ Last edited by slore on 2007-2-11 at 02:12 PM ]
Floor 4 Posted 2007-02-11 22:27 ·  中国 吉林 四平 联通
高级用户
★★★
Credits 859
Posts 413
Joined 2006-08-14 21:55
19-year member
UID 60532
Status Offline
I mainly want to learn VBS and how to use it to achieve this function? Actually, it was originally for learning. Brother above, can you write out the entire code? Text reading using VBS is exactly what I want to learn now
Floor 5 Posted 2007-02-12 02:39 ·  中国 陕西 西安 电信
铂金会员
★★★★
Credits 5,212
Posts 2,478
Joined 2007-02-08 23:39
19-year member
UID 79003
Gender Male
Status Offline
Const ForReading = 1
Const ForWriting = 2

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("d:\slorelee\桌面\test.txt", ForReading)

strText = objFile.ReadAll
objFile.Close
Recent Ratings for This Post ( 1 in total) Click for details
RaterScoreTime
anqing +8 2007-02-12 12:21
Floor 6 Posted 2007-02-12 06:11 ·  中国 吉林 四平 联通
高级用户
★★★
Credits 859
Posts 413
Joined 2006-08-14 21:55
19-year member
UID 60532
Status Offline
I read while referring to the command introduction to deepen my understanding, but my understanding is still insufficient.
Floor 7 Posted 2007-02-12 11:53 ·  中国 安徽 宣城 电信
中级用户
★★
Credits 397
Posts 168
Joined 2006-10-08 10:07
19-year member
UID 64934
Status Offline
Are you going to check how many or the specific path?
Newcomer asks first
Floor 8 Posted 2007-02-12 11:56 ·  中国 吉林 四平 联通
高级用户
★★★
Credits 859
Posts 413
Joined 2006-08-14 21:55
19-year member
UID 60532
Status Offline
Floor 9 Posted 2007-02-12 11:57 ·  中国 吉林 四平 联通
高级用户
★★★
Credits 859
Posts 413
Joined 2006-08-14 21:55
19-year member
UID 60532
Status Offline
No matter whether you are a novice or not, I appreciate any response!!! Because I am asking and you are answering!
Floor 10 Posted 2007-02-12 14:07 ·  中国 陕西 西安 电信
铂金会员
★★★★
Credits 5,212
Posts 2,478
Joined 2007-02-08 23:39
19-year member
UID 79003
Gender Male
Status Offline
Batch file:

@echo off
dir /s /b C\*.exe>Allexe.txt
:Can be used in other disks at home>>Append
cscript vbsfile.vbs
type 11.exe.txt
pause>nul


VBSFile.vbs file:

Const ForReading = 1
Const ForWriting = 2

Set objFSO = Createobject("Scripting.Filesystemobject")

Set objFile = objFSO.OpenTextFile("allexe.txt", ForReading)
Set OutFile = objFSO.OpenTextFile("11.exe.txt", ForWriting,True)

Dim num
num=0
Do While objFile.AtEndOfStream<>True
strText = objFile.Readline

If Mid(Instrrev(strText,"\")+1,5)="11.exe" Then
Msgbox strText
num=num+1
OutFile.Writeline strText
End If
Loop

OutFile.Writeline " Total found " & num & " 11.exe files"
OutFile.Close
objFile.Close
Floor 11 Posted 2007-02-12 17:57 ·  中国 浙江 杭州 电信
初级用户
Credits 128
Posts 31
Joined 2006-10-23 08:05
19-year member
UID 67855
Gender Male
Status Offline
I also wrote one that can search all partitions. The code is as follows. Save it as any.vbs file and double-click it. Friends who find it troublesome can download the attachment. (Note: Please run it in the root directory of the disk.)



On Error Resume Next 'Ignore all errors

Dim filename 'Declare variable
Dim re
Set re=New RegExp 'Create an instance of the regular expression object

re.Pattern="^(|)+\:\\\w+\.vbs$"
If re.Test(WScript.ScriptFullName)=False Then
MsgBox "Please run this program in the root directory of the disk, otherwise the search results may be incorrect!",,"MessageBox"
WScript.Quit
End If

'Declare the matching pattern of the regular expression, mainly used to check whether the file name entered by the user is correct
re.Pattern="^(|)+\.{1,4}$"
Do
filename=InputBox("Please enter the file name you want to search for:","MessageBox")
If filename="" Then WScript.Quit 'If the input is empty, exit the script
If re.Test(filename)=False Then
MsgBox "Please enter a legal file name!",,"MessageBox"
End If
Loop While re.Test(filename)=False 'Jump out of the loop until the user enters the correct file name.

Set re=Nothing

'Create an IE object to display the search status
Dim ie
Set ie=WScript.CreateObject("internetexplorer.application")

ie.menubar=0 'Do not display the menu bar of the IE object
ie.AddressBar=0 'Do not display the address bar of the IE object
ie.ToolBar=0 'Do not display the toolbar of the IE object
ie.StatusBar=0 'Do not display the status bar of the IE object
ie.FullScreen=1 'Make the IE object full screen
ie.Width=640 'Set the width of the IE object
ie.Height=120 'Set the height of the IE object
ie.Resizable=0 'Set whether the size of the IE object can be changed
ie.Navigate "about:blank" 'Set the default page pointed to by the IE object
'Set the left margin of the IE object
ie.Left=Fix((ie.Document.parentwindow.screen.availwidth-ie.Width)/2)
'Set the right margin of the IE object
ie.top=Fix((ie.document.parentwindow.screen.availheight-ie.height)/2)
ie.visible=1 'Set whether the IE object is visible

'Write to the page in the IE object below, which is no different from general HTML
With ie.Document
.write "<html>"
.write "<head>"
.write "<title>File scanning status</title>"
.write "<meta http-equiv=""content-type"" content=""text/html;charset=gb2312"">"
.write "<style><!--"
.write "body { background:#000000;text-align:center;margin:0px auto; }"
.write "* { font-family:Arial;font-size:9pt;color:#00cc00;line-height:140%; }"
.write "a:link,ahover,a:visited { text-decoration:none; }"
.write "#scanstatus { text-align:left;margin:15px; }"
.write "#header { width:100%;height:20px; }"
.write "#middle { width:100%;height:50px; }"
.write "#footer { width:100%;height:20px;text-align:right; }"
.write "--></style>"
.write "</head>"
.write "<body scroll=no>"
.write "<div id=""scanstatus"">"
.write "<div id=""header"">Starting the search program...</div>"
.write "<div id=""middle""></div>"
.write "<div id=""footer""><a href=""#"" onclick=""window.close()"">Exit program</a></div>"
.write "</div>"
.write "</body>"
.write "</html>"
End With

'Define the file system object variable
Dim fso
Dim objfolder
Dim objsubfolders
Dim objsubfolder
Dim objfiles
Dim objfile
Dim objdrives
Dim objdrive
Dim objtextfile
Dim str:str=""
Dim i:i=0 'Counter variable
Dim result
result="C:\Search Results.html" 'Search result save file variable

'Function to traverse hard disk files
Function search(path)
Set objfolder=fso.getfolder(path) 'Get the current path
Set objfiles=objfolder.Files 'Get the collection of all files in the current path
For Each objfile In objfiles 'Start traversing the file collection
'Write the current searched file path into the DIV with ID middle
ie.Document.getElementById("middle").innerHTML=objfile.Path
'If the current file name is consistent with the file name entered by the user
If objfile.Name=filename Then
i=i+1 'Counter plus one
str=str & objfile.Path & "<br>"
'Create a text stream object, the file name is the string stored in variable result
Set objtextfile=fso.OpenTextFile(result,2,True)
'Write the file path in variable str into the html file
objtextfile.Write(str)
objtextfile.Close 'Close the text stream object
Set objtextfile=Nothing 'Destroy the object
End If
If i>0 Then
ie.Document.getElementById("header").innerHTML="Found " & i & " matches, and the detailed information has been saved in the """ & result & """ file..."
Else
ie.Document.getElementById("header").innerHTML="Performing file search..."
End If
WScript.Sleep(20)
Next
Set objsubfolders=objfolder.SubFolders 'Get the collection of all folders in the current path
For Each objsubfolder In objsubfolders 'Traverse the folders
nowpath=path & "\" & objsubfolder.Name 'Get the new file path
search nowpath 'Call the function itself, start searching from the new path
Next
End Function

Set fso=CreateObject("scripting.filesystemobject")
Set objdrives=fso.Drives 'Get all disk drives of the current computer
For Each objdrive In objdrives 'Traverse the disks
search objdrive 'Call the function
Next

'Information displayed at the end
ie.Document.getElementById("header").innerHTML="Scanning completed..."
If i>0 Then
ie.Document.getElementById("middle").innerHTML="Please open """ & result & """ to view the detailed search results!"
Else
ie.Document.getElementById("middle").innerHTML="No file to search found!"
End If

'Destroy object variables and release memory space

Set objdrives=Nothing
Set objfiles=Nothing
Set objfile=Nothing
Set objdrive=Nothing
Set objfolders=Nothing
Set objfolder=Nothing
Set objsubfolders=Nothing
Set objsubfolder=Nothing
Set fso=Nothing



By the way, comments are also added. But there is still a problem now that some directories are skipped before searching. I don't know if it's a permission issue or something.

[ Last edited by 112183883 on 2007-2-12 at 07:11 PM ]
Recent Ratings for This Post ( 2 in total) Click for details
RaterScoreTime
jmz573515 +4 2007-02-13 04:50
redtek +10 2007-02-13 14:04
Attachments
Fsearch.rar (2.26 KiB, Credits to download 1 pts, Downloads: 44)
Floor 12 Posted 2007-02-12 21:25 ·  中国 吉林 四平 联通
高级用户
★★★
Credits 859
Posts 413
Joined 2006-08-14 21:55
19-year member
UID 60532
Status Offline
This VBS script is really hard to understand. Why does it involve web pages inside?
Floor 13 Posted 2007-02-13 04:50 ·  中国 辽宁 本溪 联通
银牌会员
★★★
Credits 1,212
Posts 464
Joined 2006-12-13 21:11
19-year member
UID 73417
Gender Male
Status Offline
Learning
Floor 14 Posted 2007-02-13 09:36 ·  中国 浙江 杭州 电信
初级用户
Credits 128
Posts 31
Joined 2006-10-23 08:05
19-year member
UID 67855
Gender Male
Status Offline
The IE object is just used for writing the interface and so on.

[ Last edited by 112183883 on 2007-2-13 at 09:39 AM ]
Floor 15 Posted 2007-02-13 10:30 ·  中国 吉林 四平 联通
高级用户
★★★
Credits 859
Posts 413
Joined 2006-08-14 21:55
19-year member
UID 60532
Status Offline
It runs, and it's really beautiful.
Forum Jump: