vb脚本:尝试打开命令提示符,导航到目录并运行命令

时间:2011-05-31 12:46:00

标签: vbscript dos

我需要编写一个查找目录的脚本,找到最新的.zip文件(那里有.zip和.log)然后在另一个目录中打开命令提示符并运行以下命令:

loaddb.bat -Dlc.file="C:\Program Files\XyEnterprise\SDL LiveContent\data_old\export\<name of the newest file.zip>" -Dlc.pswd=<oor password> RESTORE

我们无法安装任何语言,因此必须能够在Windows 2003&amp; 2008服务器所以我选择了vbscript ...

我有一切与运行命令不同,似乎无法解决它。

我的代码如下:

Dim fileNewest
Dim fso
Set fso = WScript.CreateObject("Scripting.FileSystemObject")
Set oFolder = fso.GetFolder("C:\Program Files\XyEnterprise\SDL LiveContent\data\export")

For Each aFile In oFolder.Files
sExtension = fso.GetExtensionName(aFile.Name)
    If sExtension = "log" Then
            'Msgbox "The file extension is a " & sExtension
        Else
            'Msgbox "The file extension is a " & sExtension
                         If fileNewest = "" Then
                        Set fileNewest = aFile  
                     Else
                     If fileNewest.DateCreated < aFile.DateCreated Then
                            Set fileNewest = aFile
                     End If
                    End If
                End If
Next
Msgbox "The Newest File in the folder is " & fileNewest.Name & chr(13) & "Size: " & fileNewest.Size & " bytes" & chr(13) & "Was last modified on " & FileNewest.DateLastModified 

Dim objShell
Set objShell = CreateObject("WScript.Shell")
objShell.Run "%comspec% /k c: & cd ../../../Program Files\XyEnterprise\SDL LiveContent\data\export"

如何在打开Dos提示符后运行命令?

谢谢,

编辑:

在Alex K的帮助下添加答案:

objShell.Run "%comspec% /k c: & cd ""C:\Program Files (x86)\XyEnterprise\SDL LiveContent\"" & """"loaddb RESTORE -Dlc.file=C:\PROGRA~2\XYENTE~1\SDLLIV~1\data\Import\" & fileNewest.Name & " -Dlc.pswd=N2kAs72z"""""

1 个答案:

答案 0 :(得分:2)

您需要引用该路径,因为它包含空格;

objShell.Run "%comspec% /k c: & cd ""../../../Program Files\XyEnterprise\SDL LiveContent\data\export"""