中国DOS联盟论坛

China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --
Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
Guest | Log in | Register | Members | Search | China DOS Union
中国DOS联盟论坛
The time now is 2026-08-01 23:14
48,037 topics / 350,122 posts / today 2 new / 48,250 members
DOS批处理 & 脚本技术(批处理室) » How to call a VBS dialog in the DOS command line
Printable Version  1,778 / 9
Floor1 hdshjffdd Posted 2006-07-31 15:05
初级用户 Posts 53 Credits 131
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?
Floor2 3742668 Posted 2006-08-01 12:23
荣誉版主 Posts 718 Credits 2,013
Save the above code as: Open File.vbs

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.
Floor3 zh159 Posted 2006-08-01 16:55
金牌会员 Posts 1,467 Credits 3,687
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?
Floor4 3742668 Posted 2006-08-01 22:00
荣誉版主 Posts 718 Credits 2,013
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:


As for how to call and output the result in batch processing, the method is still the same as in 2F.
Floor5 zh159 Posted 2006-08-01 22:47
金牌会员 Posts 1,467 Credits 3,687
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.
Floor6 3742668 Posted 2006-08-01 22:57
荣誉版主 Posts 718 Credits 2,013
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.
Floor7 zh159 Posted 2006-08-01 23:21
金牌会员 Posts 1,467 Credits 3,687
Does the script on floor 4 have to input at least two files each time, and can't it input one or more?
Floor8 zh159 Posted 2006-08-02 10:57
金牌会员 Posts 1,467 Credits 3,687
Also: The script on the 4th floor cannot input long file names containing spaces
Floor9 3742668 Posted 2006-08-02 11:39
荣誉版主 Posts 718 Credits 2,013
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.
Floor10 zh159 Posted 2006-08-02 12:58
金牌会员 Posts 1,467 Credits 3,687
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?
[ Contact the Union admin team - 中国DOS联盟 - Standard version ]
Sponsored by ifanr Inc | © 2001–2023