Question about Moving/Renaming Files in VBScript

I have a VBScript coded to pull all TXT files from a specific directory, and move/rename them with a prepended "SD-" in front of the filename.

Here is the current VB code:

Dim objFSO
Set objFSO = CreateObject("Scripting.FileSystemObject")

Dim strCurrentFolder
strCurrentFolder = "c:\HWM\MachineData"
Dim objFolder
Set objFolder = objFSO.GetFolder(strCurrentFolder)

ListDirectory objFolder

Sub ListDirectory(objFolder)
  Dim objFile
  Dim objSubFolder

  For Each objFile In objFolder.Files
    If UCase(Right(objFile.Path, 3)) = "TXT" Then
        objFSO.MoveFile objFile.Path, "SD-" & objFile.Name
    End If  
End Sub

The problem is, the files are being moved to wherever my script is run from, and I want them moved to a specific path.  I've went round and round, but it seems like when I have the specific destination path right, it breaks the move.

All help appreciated!
Who is Participating?
Patrick MatthewsCommented:
       objFSO.MoveFile objFile.Path, "c:\folder\subfolder\SD-" & objFile.Name
imsysadminAuthor Commented:
Thank you matthew, worked perfect!
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.