|
hdshjffdd
初级用户
 
积分 131
发帖 53
注册 2006-7-31
状态 离线
|
『楼 主』:
如何在DOS命令行调用VBS的对话
使用 LLM 解释/回答一下
set objFile = CreateObject("SAFRCFileDlg.FileOpen")
intRet = objFile.OpenFileOpenDlg
wscript.echo intRet, objFile.FileName
如何将选中的文件加入命令行的变量中去,以便调用?
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?
|
|
2006-7-31 15:05 |
|
|
3742668
荣誉版主
      
积分 2013
发帖 718
注册 2006-2-18
状态 离线
|
『第 2 楼』:
使用 LLM 解释/回答一下
把上述代码保存为: 打开文件.vbs
@echo off
for /f "tokens=*" %%i in ('"cscript //nologo 打开文件.vbs"') do echo %%i
如果你只是要显示文件名的话建议修改vbs脚本最后一句为Wscript.StdOut.Write objFile.FileName,虽然用wscript的echo方法和用wscript.stdout对象的write方法效果看起来是一样的,不过,建议用cscript解析的脚本最好是用后者来控制输出流。
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.
|
|
2006-8-1 12:23 |
|
|
zh159
金牌会员
     
积分 3687
发帖 1467
注册 2005-8-8
状态 离线
|
『第 3 楼』:
使用 LLM 解释/回答一下
参照楼主的VBS脚本,如何扩展为一次打开多个文件并输出每个文件绝对路径,以及单独获取每个的文件名?
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?
|
|
2006-8-1 16:55 |
|
|
3742668
荣誉版主
      
积分 2013
发帖 718
注册 2006-2-18
状态 离线
|
『第 4 楼』:
使用 LLM 解释/回答一下
关于一次选择多个文件,目前microsoft官方给出的唯一方法为指定UserAccounts.CommonDialog对象的flags属性,例如:
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
至于如何在批处理中来调用输出结果,方法还是同2F。
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.
|
|
2006-8-1 22:00 |
|
|
zh159
金牌会员
     
积分 3687
发帖 1467
注册 2005-8-8
状态 离线
|
『第 5 楼』:
使用 LLM 解释/回答一下
谢谢3742668版主的解答
另,我获得的绝对路径如:“D:\AAA\BBB\CCC.txt”,如何在批处理中单独提取其中的文件名(就是去除路径,路径不一定相同)?但需要绝对路径、单独的文件名两组数据使用。
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.
|
|
2006-8-1 22:47 |
|
|
3742668
荣誉版主
      
积分 2013
发帖 718
注册 2006-2-18
状态 离线
|
『第 6 楼』:
使用 LLM 解释/回答一下
对于%~ni等变量扩展用法请仔细查看 for /?
另外,FOR 变量参照的替换已被增强。您现在可以使用下列
选项语法:
~I - 删除任何引号("),扩充 %I
%~fI - 将 %I 扩充到一个完全合格的路径名
%~dI - 仅将 %I 扩充到一个驱动器号
%~pI - 仅将 %I 扩充到一个路径
%~nI - 仅将 %I 扩充到一个文件名
%~xI - 仅将 %I 扩充到一个文件扩展名
%~sI - 扩充的路径只含有短名
%~aI - 将 %I 扩充到文件的文件属性
%~tI - 将 %I 扩充到文件的日期/时间
%~zI - 将 %I 扩充到文件的大小
%~$PATH:I - 查找列在路径环境变量的目录,并将 %I 扩充
到找到的第一个完全合格的名称。如果环境变量名
未被定义,或者没有找到文件,此组合键会扩充到
空字符串
可以组合修饰符来得到多重结果:
%~dpI - 仅将 %I 扩充到一个驱动器号和路径
%~nxI - 仅将 %I 扩充到一个文件名和扩展名
%~fsI - 仅将 %I 扩充到一个带有短名的完整路径名
%~dp$PATH:i - 查找列在路径环境变量的目录,并将 %I 扩充
到找到的第一个驱动器号和路径。
%~ftzaI - 将 %I 扩充到类似输出线路的 DIR
在以上例子中,%I 和 PATH 可用其他有效数值代替。%~ 语法
用一个有效的 FOR 变量名终止。选取类似 %I 的大写变量名
比较易读,而且避免与不分大小写的组合键混淆。
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.
|
|
2006-8-1 22:57 |
|
|
zh159
金牌会员
     
积分 3687
发帖 1467
注册 2005-8-8
状态 离线
|
『第 7 楼』:
使用 LLM 解释/回答一下
4 楼脚本每次必须最少输入两个文件,不能输入一个或多个么?
Does the script on floor 4 have to input at least two files each time, and can't it input one or more?
|
|
2006-8-1 23:21 |
|
|
zh159
金牌会员
     
积分 3687
发帖 1467
注册 2005-8-8
状态 离线
|
『第 8 楼』:
使用 LLM 解释/回答一下
还有:4 楼脚本不能输入含有空格的长文件名
Also: The script on the 4th floor cannot input long file names containing spaces
|
|
2006-8-2 10:57 |
|
|
3742668
荣誉版主
      
积分 2013
发帖 718
注册 2006-2-18
状态 离线
|
『第 9 楼』:
使用 LLM 解释/回答一下
1,对于至少选择两个文件的情况,你可以自己加个if语句来判断,光拷贝别人的代码又能有多大提高呢?
2,不是不能输入含有空格的长文件名,而是自动把长文件名替换成了8.3的短名。
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.
|
|
2006-8-2 11:39 |
|
|
zh159
金牌会员
     
积分 3687
发帖 1467
注册 2005-8-8
状态 离线
|
『第 10 楼』:
使用 LLM 解释/回答一下
Originally posted by 3742668 at 2006-8-2 11:39:
1,对于至少选择两个文件的情况,你可以自己加个if语句来判断,光拷贝别人的代码又能有多大提高呢?
2,不是不能输入含有空格的长文件名,而是...
我说的是多次调用VBS,在输入框中每次输入单个或者多个文件
1、
set objFile = CreateObject("SAFRCFileDlg.FileOpen")
intRet = objFile.OpenFileOpenDlg
Wscript.StdOut.Write objFile.FileName
这个只能每次输入单个文件
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
而这个只能每次最少输入两个文件,单个不行
如果修改某些参数可以单独输入一个文件,但再输入两个以上时,得出N+1个变量,第一个为空
另:第二个能不能不自动把长文件名替换成了8.3的短名?
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?
|
|
2006-8-2 12:58 |
|