AllExperts > VB Script 
Search      
VB Script
Volunteer
Answers to thousands of questions
 Home · More VB Script Questions · Answer Library  · Encyclopedia ·
More VB Script Answers
Question Library

Ask a question about VB Script
Volunteer
Experts of the Month
Expert Login

Awards

About Us
Tell friends
Link to Us
Disclaimer

 
 
 
 
About Subbu
Expertise
I can answer VB Script questions which are related to Visual Basic / VBA / QTP Scripts.

Experience
8 Years

Education/Credentials
Master of Computer Applications

Awards and Honors
Established Member from QA Forums and Brainbench certification

 
   

You are here:  Experts > Computing/Technology > Basic > VB Script > VBScript to move a file using a wildcard

VB Script - VBScript to move a file using a wildcard


Expert: Subbu - 6/11/2009

Question
QUESTION: Hello:

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


You can also use Move command in place of copy.

Subbu.


Add to this Answer   Ask a Question


 
User Agreement | Privacy Policy | Kids' Privacy Policy | Help
Copyright  © 2008 About, Inc. AllExperts, AllExperts.com, and About.com are registered trademarks of About, Inc. All rights reserved.