Question about Moving/Renaming Files in VBScript

Posted on 2007-10-10
Last Modified: 2013-04-20
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!
Question by:imsysadmin
    LVL 92

    Accepted Solution

           objFSO.MoveFile objFile.Path, "c:\folder\subfolder\SD-" & objFile.Name
    LVL 1

    Author Comment

    Thank you matthew, worked perfect!

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    Displaying an arrayList in a listView using the default adapter is rarely the best solution. To get full control of your display data, and to be able to refresh it after editing, requires the use of a custom adapter.
    You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
    Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
    Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

    754 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now