Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Microsoft Dynamics GP (Archived)

IM - VB script to rename source file

(0) ShareShare
ReportReport
Posted on by 1,069

I am trying to use the "Renaming a Source File that Uses Today's Date in its Name" from the IM Script Library but am running into a syntax problem.  I'm pretty sure it is because I have a space in the file name, but not sure how to correct.  The error occurs on Line 12:

' Added by the IM Script Library
' Category: General Purpose Scripts
' Script Type: After Query Script

'Set the Path & Filename of the Source file and the Destination
'file. In this example, the destination file is named "Done 20000829",
'where "20000829" represents the system date, in the following
'format: yyyymmdd.

sSourceFile = "\\2k3-dfsql\Payroll\ABC AP_Upload.txt"

sDestinationFile = "\\2k3-dfsql\Payroll\Backup Garnishments\ABC AP_Upload & Year(Date) & Right("0" & Month(Date), 2) & Right("0" & Day(Date), 2) & ".txt"

'Create a File System Object

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

'Copy and rename the file
'The "True" parameter indicates that if the file already exists
'in the destination, then it will be overwritten

Call pFSO.CopyFile(sSourceFile, sDestinationFile, True)

Thank you for your help!

*This post is locked for comments

  • Verified answer
    WindyCityGP Profile Picture
    1,069 on at
    RE: IM - VB script to rename source file

    Correct, Ian.  Once I changed it to the following, it worked fine:

    sSourceFile = "\\2k3-dfsql\Payroll\ABC AP_Upload.txt"

    sDestinationFile = "\\2k3-dfsql\Payroll\Backup Garnishments\ABC AP_Upload" & Year(Date) & Right("0" & Month(Date), 2) & Right("0" & Day(Date), 2) & ".txt"

    'Create a File System Object

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

    'Copy and rename the file
    'The "True" parameter indicates that if the file already exists
    'in the destination, then it will be overwritten

    Call pFSO.CopyFile(sSourceFile, sDestinationFile, True)

  • Suggested answer
    Ian Grieve Profile Picture
    22,784 on at
    RE: IM - VB script to rename source file

    I'm figuring it was the missing double quote from after ABC AP_Upload?

  • WindyCityGP Profile Picture
    1,069 on at
    RE: IM - VB script to rename source file

    Figured it out.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Jainam Kothari – Community Spotlight

We are honored to recognize Jainam Kothari as our June 2025 Community…

Congratulations to the May Top 10 Community Leaders!

These are the community rock stars!

Announcing the Engage with the Community forum!

This forum is your space to connect, share, and grow!

Leaderboard > 🔒一 Microsoft Dynamics GP (Archived)

#1
Almas Mahfooz Profile Picture

Almas Mahfooz 3 User Group Leader

Featured topics

Product updates

Dynamics 365 release plans