Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Command Prompt within vb script. 2

Status
Not open for further replies.

roboyle

Technical User
Oct 5, 2011
6
US
Hi Guys-

Really new to vb scripting.
Trying to run a command prompt within vb script.

Dim fso,f,ext,firstChar,numOfPics,workingFolder,newFileName

workingFolder = "."
numOfPics = 0
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.GetFolder(workingFolder)
For Each file In f.Files
firstChar = mid(file.Name,1,1)
ext = mid(file.Name,(len(file.Name) - 2),3)
if firstChar = "P" and ext = "JPG" then
numOfPics = numOfPics + 1
newFileName = mid(file.Name,2,len(file.Name) - 1)
fso.MoveFile workingFolder & "\" & file.Name, workingFolder & "\" & newFileName
end if


Next
wscript.echo "Total renamed pics: " & numOfPics
Set fso = Nothing


DIM objShell
set objShell = wscript.createObject("wscript.shell")
iReturn = objShell.Run("%COMSPEC%/K Dir z:\Photgraph\convert -resize 120x150 *.jpg *)

The first part of the script works fine, renames image files. I'm trying to set up the second part to run a command prompt which resizes those images.



DIM objShell
set objShell = wscript.createObject("wscript.shell")
iReturn = objShell.Run("%COMSPEC%/K Dir z:\Photgraph\convert -resize 120x150 *.jpg *)

Any help would be greatly appreciated.
 
suggetion

Code:
[red][s]'firstChar = mid(file.Name,1,1)[/s][/red]
firstChar = left(file.Name, 1)

[red][s]'ext = mid(file.Name,(len(file.Name) - 2),3)[/s][/red]
ext = right(file.Name, 3)

If statements are case sensitive. Make sure you code for any case by forcing one.
Code:
if [red]ucase([/red]firstChar[red])[/red] = "P" and [red]ucase([/red]ext[red])[/red] = "JPG" then

I think it might be incidental but where is your closing quote?
Code:
iReturn = objShell.Run("%COMSPEC%/K Dir z:\Photgraph\convert -resize 120x150 *.jpg *[red][b]"[/b][/red])

-Geates

"I hope I can chill and see the change - stop the bleed inside and feel again. Cut the chain of lies you've been feeding my veins; I've got nothing to say to you!"
-Infected Mushroom

"I do not offer answers, only considerations."
- Geates's Disclaimer
 
Thanks for the help.

I included the end quote and ran again. Receiving an error message:

Script: Z:\Photograph\renamefiles.vbs
Line: 4
Char: 1
Error the system cannot find the file specified.
Code: 80070002
Source: null

I don't why it's pointing to renamefiles.vbs?
 
It's not pointing to renamefiles.vbs. It's the name of the script where the error occur. Is your script not name 'renamefiles.vbs'?

The error suggests the cmd is being interpreted as Dir z:\Photgraph\convert -resize 120x150 *.jpg *. This looks to me like two commands. Issue one at a time. Which arugments go with which command?

Code:
objShell.Run("z:\photograph\convert -resize 120x150 *.jpg", true) 'true = wait until this command has completed before continuing
objShell.Run("%COMSPEC /k dir *.jpg")

-Geates

"I hope I can chill and see the change - stop the bleed inside and feel again. Cut the chain of lies you've been feeding my veins; I've got nothing to say to you!"
-Infected Mushroom

"I do not offer answers, only considerations."
- Geates's Disclaimer
 
Thanks Geates-
Yes the file is named renamefiles.vbs

I apologize for the lack of knowledge.

I'm trying to tell the cmd to run when it's in the 'z:photograph' folder. The 'convert -resize 120x150 *.jpg' is part of ImageMagick cmd for re-sizing images.

I'm not intentionally trying to give it two commands.

Rich
 
So, you wanted this ?
iReturn = objShell.Run("%COMSPEC% /K CD z:\Photograph & convert -resize 120x150 *.jpg", 1, True)

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Yes, this is correct.

It is hitting the z:\Photograph folder, but instead of running the 'convert -resize 120x150 *.jpg' command, it just opens a command prompt.
 
Works great now with a small exception.
The command prompt remains open after it's run.
The rename script won't run until it closes.

Thanks again for all of your help!
 
The command prompt remains open after it's run
iReturn = objShell.Run("%COMSPEC% /[!]C[/!] CD z:\Photograph & convert -resize 120x150 *.jpg", 1, True

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Why go through the indirection of running a command processor just to run a program? You aren't using any StdIO redirection so it should not be necessary.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top