Wednesday, July 13, 2011

Creatign BAT file

With this code we can create a bat file with a list of files in a folder.

On Error Resume Next
dim outfile
dim str
set fileobj=Createobject("Scripting.FileSystemObject")
objStartFolder = "."
Set objFolder = fileobj.GetFolder(objStartFolder)
Set colFiles = objFolder.Files
set outfile=fileobj.opentextfile(objFolder.Path &"\script.bat",8,true)
For Each objFile in colFiles
If UCase(Right(objFile.Name, 4)) = ".DOC" Then
outfile.WriteLine("c:\some.exe " & chr(34) & objFile.Name & Chr(34) & " bla bla bla ")
End IF
'outfile.WriteLine("total number of doc files = "&i)

If Err.number <> 0 Then
    'Msgbox "Unexpected Error" & vbCrlF &vbCrLf & Err.Description
End If

1 comment:

  1. Hello friends,

    BAT are simple text documents that run sets of commands. When you open a batch file MS command runs the commands. Batch commands, like macros are useful for running a set of repetitive commands on a regular basis, reducing risk of human error. Window's inbuilt command runs batch files much like their original operation in MS-DOS. Thanks a lot....

    Data Extract