Hi Guys,
Need your help once again,
I have a script that runs fine now but the files it uses I need to change the name as at the moment the user will only put in the batch number but the file name also has the question number as part of the file name. I would like to search folders based on the batch number only as several files in the folder belong to the same batch number and I would like to retrieve files from the same batch number only.
for e.g
user putS in F117
the files in the folder are
K0019F117.txt
K0019F118.txt
K0019F116.txt
K0020F117.txt
K0019F115.txt
K0021F117.txt
K0002F117.txt
So i would like my script to only retrieve all files that end with F117
My script I am using is
Option Explicit
Dim objFSO, objFolder, objShell, objTextFile, objFile, sRead
Dim strDirectory, strFile, strText,strDirectory2, strFile2, files, file, index
strDirectory = "c:\input"
strDirectory2 = "c:\fso2\test2"
strFile = "this will come from the user as f117 but currentlty is K0019F117.txt etc "
strFile2 = "\fso.txt"
' Create the File System Object
Set objFSO = CreateObject("Scripting.FileSystemObject")
' Check that the strDirectory folder exists
If objFSO.FolderExists(strDirectory) Then
Set objFolder = objFSO.GetFolder(strDirectory)
Else
WScript.Echo " The File" & strDirectory & "does not exist"
WScript.Quit
End If
set objFile = nothing
set objFolder = nothing
Const ForAppending = 8, ForReading = 1, ForWriting = 2
set files = objFSO.GetFolder("c:\input").Files
index=1
for each file in files
if index<>5 then
Set objTextFile = objFSO.OpenTextFile _
(strDirectory & "\" THIS IS WERE I WANT THE NEW FILE NAME ie E117 TO BE, 1, True)
' Writes strText every time you run this VBScript
if index= 1 then
sRead = objTextFile.ReadAll
else
objTextFile.SkipLine
sRead = objTextFile.ReadAll
end if
objTextFile.Close
if index=1 then
Set objTextFile = objFSO.OpenTextFile _
(strDirectory2 & strFile2, 2, True)
else
Set objTextFile = objFSO.OpenTextFile _
(strDirectory2 & strFile2, 8, True)
end if
' Writes strText every time you run this VBScript
objTextFile.Write(sRead)
objTextFile.Close
index=index+1
end if
next
'objTextFile.Close
WScript.Quit
Thanks in advance
Need your help once again,
I have a script that runs fine now but the files it uses I need to change the name as at the moment the user will only put in the batch number but the file name also has the question number as part of the file name. I would like to search folders based on the batch number only as several files in the folder belong to the same batch number and I would like to retrieve files from the same batch number only.
for e.g
user putS in F117
the files in the folder are
K0019F117.txt
K0019F118.txt
K0019F116.txt
K0020F117.txt
K0019F115.txt
K0021F117.txt
K0002F117.txt
So i would like my script to only retrieve all files that end with F117
My script I am using is
Option Explicit
Dim objFSO, objFolder, objShell, objTextFile, objFile, sRead
Dim strDirectory, strFile, strText,strDirectory2, strFile2, files, file, index
strDirectory = "c:\input"
strDirectory2 = "c:\fso2\test2"
strFile = "this will come from the user as f117 but currentlty is K0019F117.txt etc "
strFile2 = "\fso.txt"
' Create the File System Object
Set objFSO = CreateObject("Scripting.FileSystemObject")
' Check that the strDirectory folder exists
If objFSO.FolderExists(strDirectory) Then
Set objFolder = objFSO.GetFolder(strDirectory)
Else
WScript.Echo " The File" & strDirectory & "does not exist"
WScript.Quit
End If
set objFile = nothing
set objFolder = nothing
Const ForAppending = 8, ForReading = 1, ForWriting = 2
set files = objFSO.GetFolder("c:\input").Files
index=1
for each file in files
if index<>5 then
Set objTextFile = objFSO.OpenTextFile _
(strDirectory & "\" THIS IS WERE I WANT THE NEW FILE NAME ie E117 TO BE, 1, True)
' Writes strText every time you run this VBScript
if index= 1 then
sRead = objTextFile.ReadAll
else
objTextFile.SkipLine
sRead = objTextFile.ReadAll
end if
objTextFile.Close
if index=1 then
Set objTextFile = objFSO.OpenTextFile _
(strDirectory2 & strFile2, 2, True)
else
Set objTextFile = objFSO.OpenTextFile _
(strDirectory2 & strFile2, 8, True)
end if
' Writes strText every time you run this VBScript
objTextFile.Write(sRead)
objTextFile.Close
index=index+1
end if
next
'objTextFile.Close
WScript.Quit
Thanks in advance