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
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 :
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)
Please log in to answer
Posted by:
anonymous_9363
14 years ago
Hint: see this DevGuru section
Ignore the ASP tags. The part you're interested in is 'GetExtensionName'.
Ignore the ASP tags. The part you're interested in is 'GetExtensionName'.
Posted by:
anonymous_9363
14 years ago
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
Rating comments in this legacy AppDeploy message board thread won't reorder them,
so that the conversation will remain readable.
so that the conversation will remain readable.