Solved

VB Script Language/ActiveX

Posted on 2009-03-31
7
285 Views
Last Modified: 2013-11-18
I need the below code to copy the file and when it does it is renaming it.  The only problem I need to modify it for a different project.  I needs to rename the file in the guard folder, but I won't know what the original filename is.  I tried doing a *.csv but that doesn't seem to work what would the correct syntax be?
'**********************************************************************

'  Visual Basic ActiveX Script

'************************************************************************
 

Function Main()
 

	dim fso

	dim d

	dim m

	dim y
 

	d = day(date)

	m = month(date)

	y =  year(date)

	

	if len(d) = 1 then d = "0" & d

	if len(m) = 1 then m = "0" & m
 

	set fso = createobject("Scripting.FileSystemObject")
 

	fso.Copyfile "C:\Clients\Strat\File Uploads\Customer Uploads\guard\test.csv", "C:\Clients\Strat\File Uploads\Customer Uploads\guard\guard.csv"

			

	Main = DTSTaskExecResult_Success
 

End Function

Open in new window

0
Comment
Question by:N R
  • 4
  • 3
7 Comments
 
LVL 67

Expert Comment

by:sirbounty
Comment Utility
rename to what?
This should do it if you're talking only one file...
'**********************************************************************

'  Visual Basic ActiveX Script

'************************************************************************

 

Function Main()

 

        dim fso

        dim d

        dim m

        dim y

 

        d = day(date)

        m = month(date)

        y =  year(date)

        

        if len(d) = 1 then d = "0" & d

        if len(m) = 1 then m = "0" & m

 

        set fso = createobject("Scripting.FileSystemObject")

        strFolder = "C:\Clients\Strat\File Uploads\Customer Uploads\guard\"

        For Each File in objFSO.GetFolder(strFolder).Files

          fso.Copyfile file, strFolder & "guard.csv"

        Next                      

        Main = DTSTaskExecResult_Success

 

End Function

Open in new window

0
 
LVL 11

Author Comment

by:N R
Comment Utility
I want it renamed to guard.csv from whatever it is currently named in the guard folder.  That script gave me and error:

Error Source: Microsoft Data Transformation Services(DTS) Package

Error Description: Error Code: 0
Error Source= Microsoft VBScript runtime error
Error Description: Object required: 'objFSO'

Error on Line 20
0
 
LVL 67

Accepted Solution

by:
sirbounty earned 500 total points
Comment Utility
sorry - try this...
'**********************************************************************

'  Visual Basic ActiveX Script

'************************************************************************

 

Function Main()

 

        dim fso

        dim d

        dim m

        dim y

 

        d = day(date)

        m = month(date)

        y =  year(date)

        

        if len(d) = 1 then d = "0" & d

        if len(m) = 1 then m = "0" & m

 

        set fso = createobject("Scripting.FileSystemObject")

        strFolder = "C:\Clients\Strat\File Uploads\Customer Uploads\guard\"

        For Each File in fso.GetFolder(strFolder).Files

          fso.Copyfile file, strFolder & "guard.csv"

        Next                      

        Main = DTSTaskExecResult_Success

 

End Function

Open in new window

0
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 11

Author Comment

by:N R
Comment Utility
That renames the file, but the old file is still left there
0
 
LVL 67

Expert Comment

by:sirbounty
Comment Utility
Actually, if there are any files in that folder, this could get ugly...
Assuming you'll only have one CSV..use this:
'**********************************************************************

'  Visual Basic ActiveX Script

'************************************************************************

 

Function Main()

 

        dim fso

        dim d

        dim m

        dim y

 

        d = day(date)

        m = month(date)

        y =  year(date)

        

        if len(d) = 1 then d = "0" & d

        if len(m) = 1 then m = "0" & m

 

        set fso = createobject("Scripting.FileSystemObject")

        strFolder = "C:\Clients\Strat\File Uploads\Customer Uploads\guard\"

        For Each File in fso.GetFolder(strFolder).Files

          If lcase(fso.getextensionname(file.name)) = "csv" Then fso.Copyfile file, strFolder & "guard.csv"

        Next                      

        Main = DTSTaskExecResult_Success

 

End Function

Open in new window

0
 
LVL 67

Assisted Solution

by:sirbounty
sirbounty earned 500 total points
Comment Utility
Oh, if you're trying to simply rename, use .MoveFile, not .CopyFile...
0
 
LVL 11

Author Closing Comment

by:N R
Comment Utility
Works Great Thanks
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

This script will sweep a range of IP addresses (class c only, 255.255.255.0) and report to a log the version of office installed. What it does: 1.)      Creates log file in the directory the script is run from (if it doesn't already exist) 2.)      Sweep…
Before we dive into the marketing strategies involved with creating an effective homepage, it’s crucial that EE members know what a homepage is. In essence, a homepage is the introductory, or default page, of a website that typically highlights the …
The purpose of this video is to demonstrate how to set up the WordPress backend so that each page automatically generates a Mailchimp signup form in the sidebar. This will be demonstrated using a Windows 8 PC. Tools Used are Photoshop, Awesome…
This video discusses moving either the default database or any database to a new volume.

771 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

14 Experts available now in Live!

Get 1:1 Help Now