/build/static/layout/Breadcrumb_cap_w.png

VBscript : list files in folder with extra text as output

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   [ + ] Show comments

Answers (4)

Posted by: anonymous_9363 13 years ago
Red Belt
0
Hint: see this DevGuru section

Ignore the ASP tags. The part you're interested in is 'GetExtensionName'.
Posted by: anonymous_9363 13 years ago
Red Belt
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
Posted by: bacaryu 13 years ago
Yellow Belt
0
thank you very much, that did the trick :)
Posted by: bacaryu 13 years ago
Yellow Belt
0
Just one last question.

Is it possible to filter only *.trn files ?
Rating comments in this legacy AppDeploy message board thread won't reorder them,
so that the conversation will remain readable.
 
This website uses cookies. By continuing to use this site and/or clicking the "Accept" button you are providing consent Quest Software and its affiliates do NOT sell the Personal Data you provide to us either when you register on our websites or when you do business with us. For more information about our Privacy Policy and our data protection efforts, please visit GDPR-HQ