Solved

VB Script Language/ActiveX

Posted on 2009-03-31
7
293 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:Nathan Riley
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 
LVL 67

Expert Comment

by:sirbounty
ID: 24031640
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:Nathan Riley
ID: 24031673
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
ID: 24031693
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 11

Author Comment

by:Nathan Riley
ID: 24031707
That renames the file, but the old file is still left there
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 24031715
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
ID: 24031720
Oh, if you're trying to simply rename, use .MoveFile, not .CopyFile...
0
 
LVL 11

Author Closing Comment

by:Nathan Riley
ID: 31564951
Works Great Thanks
0

Featured Post

Want Experts Exchange at your fingertips?

With Experts Exchange’s latest app release, you can now experience our most recent features, updates, and the same community interface while on-the-go. Download our latest app release at the Android or Apple stores today!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I made this because I wanted to get e-mail with a attached csv file so I'd would be able to import user input into a MS Excel template, but I also wanted to register/save all inputs from each day in a file on the server. 1st - It creates a temp C…
Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
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…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

623 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