How to: output to a txt file the results of a copy command from a batch file

Status
Not open for further replies.

QuaziBee

Daemon Poster
Messages
661
Location
Calgary, AB
Ahoy fellas

I'm making a basic batch script to unzip some files to 2 different directories.

Can I make that batch script output a txt file listing any files it failed to extract for any reason?
 
Sure, use the > operator to overwrite whatever's in the file and >> to append to whatever file you want.

eg:
echo Top of file > myfile.txt
dir >> myfile.txt
 
I decided to use VB because it will be more versatile for what I want to do.

End result is to enter a computer name, it checks for the existance of files on that PC, and writes the result to a file.

I don't know a good way to roll my If FileExists from the first to last elements in the array.

Here's what I have so far:

Public Class Form1
Public Function FileExists(ByVal Fname As String) As Boolean

'Defines FileExists paramater
If Fname = "" Or (Fname) = "\" Then
FileExists = False : Exit Function
End If
FileExists = (Dir(Fname) <> "")

End Function
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

'Array of files to be queried
Dim backOne() As String = {"Trnhdr.dbf", "Trnhdr.cdx", "Trndtl.dbf", "Trndtl.cdx", "Pohdr.dbf", "Podtl.dbf", "Inwksh.dat", "Indata.dbf", "Indata1.idx", "Indata2.idx", "Vendorwk.dbf", "Vendorwk.cdx", "Vendor.dbf", "Vendor.cdx", "Time.sys", "User.sys", "Comps.mdb"}

'Injected text depending on results
Dim aString As String = " Exists"
Dim bString As String = " Does NOT Exist"

'Defines true and false statements to inject
Dim trueString As String = backOne(1) & aString
Dim falseString As String = backOne(1) & bString

'TextBox1 is the store name
Dim textBox As String = TextBox1.Text

'Path to folder containing files to be queried
Dim aPath As String = "\C$\"

'If Then Else to determin if the files are present
If FileExists("\\" & textBox & aPath & backOne(1)) Then
My.Computer.FileSystem.WriteAllText("H:\logs3\Results.txt", trueString & vbCrLf, True)
Else
My.Computer.FileSystem.WriteAllText("H:\logs3\Results.txt", falseString & vbCrLf, True)
End If

End Sub
End Class

I could just write 16 result string and 16 if then elses but there has to be a slicker way.

Any advice is appreciated.
 
Figured it out.
I used:
For Each element As String In backOne

to encompass my if then else and replaced the trueString dims with element.
I also deleted the trueString and falseString as they were unnessicary.

Works like a charm.
 
Status
Not open for further replies.
Back
Top Bottom