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-01 22:11
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » How to call a VBS dialog in the DOS command line View 1,775 Replies 9
Original Poster Posted 2006-07-31 15:05 ·  中国 浙江 宁波 电信
初级用户
★★
Credits 131
Posts 53
Joined 2006-07-31 09:06
20-year member
UID 59539
Status Offline
set objFile = CreateObject("SAFRCFileDlg.FileOpen")
intRet = objFile.OpenFileOpenDlg
wscript.echo intRet, objFile.FileName

How to add the selected file to the variable of the command line for calling?
Floor 2 Posted 2006-08-01 12:23 ·  中国 湖北 荆门 电信
荣誉版主
★★★
Credits 2,013
Posts 718
Joined 2006-02-18 07:07
20-year member
UID 50550
Status Offline
Save the above code as: Open File.vbs

@echo off
for /f "tokens=*" %%i in ('"cscript //nologo 打开文件.vbs"') do echo %%i

If you just want to display the file name, it is recommended to modify the last line of the vbs script to Wscript.StdOut.Write objFile.FileName. Although the effect of using the echo method of wscript and the write method of the wscript.stdout object seems the same, it is recommended that scripts parsed with cscript should preferably use the latter to control the output stream.
Floor 3 Posted 2006-08-01 16:55 ·  中国 广西 玉林 博白县 电信
金牌会员
★★★★
Credits 3,687
Posts 1,467
Joined 2005-08-08 12:00
20-year member
UID 44210
Status Offline
Referring to the building - block's VBS script, how to expand it to open multiple files at one time and output the absolute path of each file, as well as obtain the file name of each one separately?
Floor 4 Posted 2006-08-01 22:00 ·  中国 湖北 荆门 电信
荣誉版主
★★★
Credits 2,013
Posts 718
Joined 2006-02-18 07:07
20-year member
UID 50550
Status Offline
Regarding selecting multiple files at once, the only method provided by Microsoft officially is to specify the flags property of the UserAccounts.CommonDialog object. For example:


Set objDialog = CreateObject("UserAccounts.CommonDialog")
objDialog.Filter = "VBScript Scripts|*.vbs|All Files|*.*"
objDialog.Flags = &H0200
objDialog.FilterIndex = 1
objDialog.InitialDir = "e:\"
intResult = objDialog.ShowOpen
If intResult = 0 Then
Wscript.Quit
Else
arrFiles = Split(objDialog.FileName, " ")
For i = 1 to Ubound(arrFiles)
strFile = arrFiles(0) & arrFiles(i)
Wscript.Echo strFile
Next
End If

As for how to call and output the result in batch processing, the method is still the same as in 2F.
Floor 5 Posted 2006-08-01 22:47 ·  中国 广西 玉林 博白县 电信
金牌会员
★★★★
Credits 3,687
Posts 1,467
Joined 2005-08-08 12:00
20-year member
UID 44210
Status Offline
Thanks to the moderator of version 3742668 for the explanation.

In addition, the absolute path I obtained is like: "D:\AAA\BBB\CCC.txt". How to separately extract the file name (that is, remove the path, and the path may not be the same) in the batch processing? But both the absolute path and the separate file name need to be used in two sets of data.
Floor 6 Posted 2006-08-01 22:57 ·  中国 湖北 荆门 电信
荣誉版主
★★★
Credits 2,013
Posts 718
Joined 2006-02-18 07:07
20-year member
UID 50550
Status Offline
For variable expansion usages like %~ni, please check for /? carefully.



In addition, the replacement of FOR variable references has been enhanced. You can now use the following option syntax:

~I - Remove any quotation marks ("), expand %I
%~fI - Expand %I to a fully qualified pathname
%~dI - Expand %I to only a drive letter
%~pI - Expand %I to only a path
%~nI - Expand %I to only a filename
%~xI - Expand %I to only a file extension
%~sI - The expanded path contains only the short name
%~aI - Expand %I to the file's file attributes
%~tI - Expand %I to the file's date/time
%~zI - Expand %I to the file's size
%~$PATH:I - Find the directory listed in the path environment variable and expand %I to the first found fully qualified name. If the environment variable name is not defined or the file is not found, this combination will expand to an empty string

You can combine modifiers to get multiple results:

%~dpI - Expand %I to only a drive letter and path
%~nxI - Expand %I to only a filename and extension
%~fsI - Expand %I to a complete pathname with a short name
%~dp$PATH:i - Find the directory listed in the path environment variable and expand %I to the first found drive letter and path.
%~ftzaI - Expand %I to a DIR-like output line

In the above examples, %I and PATH can be replaced with other valid values. The %~ syntax ends with a valid FOR variable name. Choosing uppercase variable names like %I is easier to read and avoids confusion with case-insensitive combination keys.
Floor 7 Posted 2006-08-01 23:21 ·  中国 广西 玉林 博白县 电信
金牌会员
★★★★
Credits 3,687
Posts 1,467
Joined 2005-08-08 12:00
20-year member
UID 44210
Status Offline
Does the script on floor 4 have to input at least two files each time, and can't it input one or more?
Floor 8 Posted 2006-08-02 10:57 ·  中国 广西 玉林 博白县 电信
金牌会员
★★★★
Credits 3,687
Posts 1,467
Joined 2005-08-08 12:00
20-year member
UID 44210
Status Offline
Also: The script on the 4th floor cannot input long file names containing spaces
Floor 9 Posted 2006-08-02 11:39 ·  中国 湖北 荆门 电信
荣誉版主
★★★
Credits 2,013
Posts 718
Joined 2006-02-18 07:07
20-year member
UID 50550
Status Offline
1. For the case of selecting at least two files, you can add an if statement by yourself to judge. How much improvement can there be just by copying others' code?
2. It's not that you can't input long file names with spaces, but that the long file names are automatically replaced with 8.3 short names.
Floor 10 Posted 2006-08-02 12:58 ·  中国 广西 玉林 博白县 电信
金牌会员
★★★★
Credits 3,687
Posts 1,467
Joined 2005-08-08 12:00
20-year member
UID 44210
Status Offline
Originally posted by 3742668 at 2006-8-2 11:39:
1, For the case of selecting at least two files, you can add an if statement by yourself to judge. How much improvement can there be by just copying others' code?
2, It's not that you can't input long file names with spaces, but...

What I'm saying is calling VBS multiple times, inputting single or multiple files in the input box
1、
set objFile = CreateObject("SAFRCFileDlg.FileOpen")
intRet = objFile.OpenFileOpenDlg
Wscript.StdOut.Write objFile.FileName

This can only input a single file each time

2、
Set objDialog = CreateObject("UserAccounts.CommonDialog")
objDialog.Filter = "VBScript Scripts|*.vbs|All Files|*.*"
objDialog.Flags = &H0200
objDialog.FilterIndex = 1
objDialog.InitialDir = "e:\"
intResult = objDialog.ShowOpen
If intResult = 0 Then
Wscript.Quit
Else
arrFiles = Split(objDialog.FileName, " ")
For i = 1 to Ubound(arrFiles)
strFile = arrFiles(0) & arrFiles(i)
Wscript.Echo strFile
Next
End If

And this can only input at least two files each time, not single ones
If you modify some parameters, you can input a single file alone, but when inputting two or more, there will be N+1 variables, and the first one is empty
In addition: Can the second one not automatically replace the long file name with the 8.3 short name?
Forum Jump: