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!

run batch DOS command

Status
Not open for further replies.

markronz

IS-IT--Management
Mar 20, 2007
93
US
Hello everyone. In short what I am trying to do is this:

Create a script that will prompt for a path. Then it will cycle through all the files and folders in that path searching for any files named "Folder.jpg" or "folder.jpg" (I'm not sure if it's case sensitive...). Then if it finds any files that have that name, I want to run this DOS command on them:
attrib -S -H

So here is what I have so far:
Code:
Dim fs, fil, fldr, strPath

Set fs = CreateObject("Scripting.FileSystemObject")
strPath = InputBox("Enter Path of folder", "Find File")

If strPath = "" Or fs.FolderExists(strPath) = False Then
    MsgBox "Not a valid folder Path.", 64
    WScript.Quit
End If

Set fldr = fs.GetFolder(strPath)

For Each fil In fldr.Files
    If fil.Name = "Folder.jpg" Then
    	'starts a dos box and runs a command
	Dim strCommand, objShell, objExec 
	strCommand = "attrib -S -H " & Chr(34) & fil.Path & Chr(34)
	Set objShell = CreateObject("WScript.Shell") 
	Set objExec = objShell.Exec(strCommand) 
    End If
Next

Can someone help me fill in the blanks as to what I am missing here? Also, some of the Folder.jpg files are hidden and system files (that's what the command is getting rid of).

Any help would be appreciated! Thanks
-Mark
 
no need to run the DOS command.

Code:
Const System = 4
Const Hidden = 2

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.GetFile("C:\testfile.txt")
objFile.Attributes = System + Hidden

I hope you find this post helpful.

Regards,

Mark

Check out my scripting solutions at
Work SMARTER not HARDER. The Spider's Parlor's Admin Script Pack is a collection of Administrative scripts designed to make IT Administration easier! Save time, get more work done, get the Admin Script Pack.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top