I trying to go from cmd script to vbscript in MS window xp
cmd code yes works
set home_=%~dp0
set part001=part001
set part002=part002
set part003=part003
set part004=part004
::get the dir in part001
for /f "delims=" %%A in ('dir /s/b/o:n/a:d ^"%home%%part001%\^"') do (
echo show have dir path
echo %%A
pause
)
echo to the end
pause
goto :eof
to vbscript
the part I do not know to convert are those that are foramtted as cmd{cmd codeing}
dim strHome as strimg =cmd{[%~dp0]}
dim strPart001 as sting = part001
dim strPart002 as sting = part002
dim strPart003 as sting = part003
dim strPart004 as sting = part004
'get the dir in part001
Dim objFSo, objFile
Set objFSo = CreateObject("Scripting.FileSystemObject")
set objDirPart001list = objFS.getfolder(strHome&strPart001\)
set subDirPart001list = objDirPart001list.SubFolders
for each subDirPart001Name in subDirPart001list
WScript.Echo show dir path
WScript.Echo part
cmd{pause}
)
cmd{pause}
what are the corresponding vbscript commands for:
- %~dp0
- pause
The
%~dp0is a so-called magic command but more technically this method is known as variable substition. The %n variables are used to reference the command line parameters of the script. The most common,%0will return the full path to the script that is executing. The d and p are special modifiers that will return the drive and path portion of that path, respectively. There is also n which returns the filename portion as well as others. These modifiers can be combined as necessary. So the%~dp0command will return the full drive and path to the directory where the executing script resides. To do this in VBScript, you can use any of the following that rely on the WScript Object’s ScriptFullName method:Or
Or my favorite:
The
pausecommand is used to stop the command interpreter and prompt the user to press any key to continue. This is typically done so that the user has time to read the information in the command window before it closes. Here’s a subroutine to do that in CScript. (For WScript, you would just use a simple MessageBox.)