/bundles/itninjaweb/img/Breadcrumb_cap_w.png
Hello I'm not a VBscripter but maybe somebody can help me

I found a script that almost does what I'm looking for. It lists all files of a folder that you select.
But I need to modify it so it so I can have a query ready to copy/paste into a MSSQL server.

Basicly it is to restore log shipping files into a MSSQL database.

so the script I found is

On Error Resume Next
Dim fso, folder, files, NewsFile,sFolder

Set fso = CreateObject("Scripting.FileSystemObject")
sFolder = Wscript.Arguments.Item(0)
If sFolder = "" Then
Wscript.Echo "No Folder parameter was passed"
Wscript.Quit
End If
Set NewFile = fso.CreateTextFile(sFolder&"\FileList.txt", True)
Set folder = fso.GetFolder(sFolder)
Set files = folder.Files

For each folderIdx In files
NewFile.WriteLine(folderIdx.Name)
Next
NewFile.Close


and the output of this will give all files of the folder in a FileList.txt file
filelist.txt contains :
TestDatabase_TransactionLogBackup1.trn
TestDatabase_TransactionLogBackup2.trn
TestDatabase_TransactionLogBackup3.trn
TestDatabase_TransactionLogBackup4.trn
TestDatabase_TransactionLogBackup5.trn

I think this is easily modifiable to give me an output like below (all the same text, only different a filename). But I don't know how to do it.

It tried something with f.WriteLine("Blablabla") then the NewFile.WriteLine(folderIdx.Name) and then the rest f.WriteLine("Blaaa").
But I can't make it work.

Output I'm looking for :

RESTORE LOG NewDatabase
FROM DISK = 'D:\BackupFiles\TestDatabase_TransactionLogBackup1.trn'
WITH NORECOVERY

RESTORE LOG NewDatabase
FROM DISK = 'D:\BackupFiles\TestDatabase_TransactionLogBackup2.trn'
WITH NORECOVERY

...
0 Comments   [ - ] Hide Comments

Comments

Please log in to comment

Rating comments in this legacy AppDeploy message board thread won't reorder them,
so that the conversation will remain readable.
Answer this question or Comment on this question for clarity

Answers

0
Untested and from memory (check the .Path property, in particular - I'm sure it returns the complete filename, including its parent folder name)Const strRestoreCmdLine = "RESTORE LOG NewDatabase FROM DISK"
Const strWithNoRecovery = "WITH NORECOVERY"
Dim strCommandLine
With NewFile
For each folderIdx In files
strCommandLine = strRestoreCmdLine & " = " & folderIdx.Path & " " & strWithNoRecovery & vbCRLF
.Write(strCommandLine)
Next
.Close
End With
Answered 09/29/2010 by: VBScab
Red Belt

Please log in to comment
0
thank you very much, that did the trick :)
Answered 09/29/2010 by: bacaryu
Yellow Belt

Please log in to comment
0
Just one last question.

Is it possible to filter only *.trn files ?
Answered 09/29/2010 by: bacaryu
Yellow Belt

Please log in to comment
0
Hint: see this DevGuru section

Ignore the ASP tags. The part you're interested in is 'GetExtensionName'.
Answered 09/29/2010 by: VBScab
Red Belt

Please log in to comment