I am trying to write a VBScript to move a file from a specific folder to a specific destination but the catch is that the file name changes everyday: TestFile###.txt where ### is a random number sequence. I have tried CopyFile and FileMove and both state “Path Not Found” due to the wild card. Is there a way to accomplish this task is VBScript. It is important to know that there will never be two files in this folder with the naming convention of TestText.
Here is the syntax that I have tried:
Dim fso
Set fso = CreateObject("Scripting.FileSystemObject")
fso.MoveFile "C:\Directory\TestFile*.txt", "C:\Directory\NewLocation\TestFile.txt", True
Set fso = Nothing
Thank you very much for your help in advance.
Regards,
Steve
ANSWER: Steve,
Try this:
dim objshell
Set objshell = CreateObject("Wscript.shell")
objshell.Run "cmd /c C:\Directory\TestFile*.txt, C:\Directory\NewLocation\TestFile.txt"
set objshell = nothing
Let me know if any issue.
Subbu.
---------- FOLLOW-UP ----------
QUESTION: Thank you very much for getting back to me so quickly. I ran this however it is not doing anything; it does not copy or move the file. Any thoughts?
Answer Steve,
I am really sorry, I forgot Copy command. Please try this and let me know.
dim objshell
Set objshell = CreateObject("Wscript.shell")
objshell.Run "cmd /c copy C:\Directory\TestFile*.txt C:\Directory\NewLocation\TestFile.txt"
set objshell = nothing