Discussion Locked

VB Script File Move

0 helpful
8 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.
I need to use Vb Script to move all .txt files from one folder to another. The file names are a variable. I have found information on how to do this when the file names are known but not when you want to move all files of a given type.

8 replies

by drhue

I tried this however it caused a syntax error/ Here is the code I am using:

dim filesys
set filesys=CreateObject("Scripting.FileSystemObject")

filesys.MoveFile "c:\edi\snd\*.txt", "c:\snd\" & dave & "\"

by cptomlly

object.MoveFile ( source, destination ); (Where "object" is a FileSystemObject). The source argument can contain a wildcard in the last component so you could use "C:\data\txtfiles\*.txt"

You can find the complete reference for MoveFile method here: http://msdn.microsoft.com/library/en-us/script56/html/jsmthMoveFile.asp

If needed, here is reference to the FileSystemObject Object: http://msdn.microsoft.com/library/en-us/script56/html/jsobjFileSystem.asp

Hope this helps.

by cptomlly

I think you are getting syntax error because of the way you are declaring the destination. Try this:

dim filesys
dim destination as Str
set destination = "c:\snd\" & dave & "\"
set filesys=CreateObject("Scripting.FileSystemObject")

filesys.MoveFile "c:\edi\snd\*.txt", destination;

This discussion is closed to new replies.