Solved

VB Script Language/ActiveX

Posted on 2009-03-31
7
287 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
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:N R
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
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
LVL 11

Author Comment

by:N R
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:N R
ID: 31564951
Works Great Thanks
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Windows Script Host failed (Access is denied.) error 6 150
Need help editing script 3 74
Custom auto number 6 65
VBScript Write Column Headers 3 38
Not long ago I saw a question in the VB Script forum that I thought would not take much time. You can read that question (Question ID  (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_28455246.html)28455246) Here (http…
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…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

803 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