Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


Help

 
Logged in as: Guest
arrSession:exec spGetSession 2,2,61666
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Help
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 Help - 6/20/2008 6:24:21 AM   
  scot

 

Posts: 3
Score: 0
Joined: 6/20/2008
Status: offline
 Hi, I'm pretty new to a lot of this and I was hoping if someone could help me out.  I'm certain that this has been covered on this forum before, but I've looked and I haven't seen anything.

I'm trying to run the code below in .vbs script.  I get an error that seems to be pointing me to the "As" section on the Dim lines.  It's a fairly simple script that I created to rename a file and works under vba conditions.  Does anyone have any suggestions?  Thanks.

Sub Interval_Datafile_Name_Change()


   Dim oApp As Object
   Dim FilePath As String, Draft As String, FinalFilePath As String
   
   Dim FileName As String
   Dim DestPath As String
  
   FilePath = "C:\Documents and Settings\My Documents\Reporting\Data\"
  
   DestPath = "C:\Documents and Settings\My Documents\Reporting\Data\"
  
   Draft = "Int_Data" & "*"
  
   FinalFilePath = FilePath & Draft
  
   FileName = Dir(FilePath & Draft, vbNormal)
  
   If FileName <> "" Then
    
   Name FilePath & FileName As DestPath & "Int_Data.xls"
  
   Else
  
   MsgBox "No Files Found"
  
   End If



End Sub
 
 
Post #: 1
 
 RE: Help - 6/20/2008 7:33:57 AM   
  dm_4ever


Posts: 2665
Score: 46
Joined: 6/29/2006
From: Orange County, California
Status: offline
With VBScript you don't define a type for your variables....

What are you trying to do? Check a file path?  If so, look for FileSystemObject and FileExists method

_____________________________

dm_4ever

My philosophy: K.I.S.S - Keep It Simple Stupid
Read Me: http://www.visualbasicscript.com/m_24727/tm.htm
Frequently Asked Stuff: http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to scot)
 
 
Post #: 2
 
 RE: Help - 6/20/2008 8:56:27 AM   
  scot

 

Posts: 3
Score: 0
Joined: 6/20/2008
Status: offline
Ok, first off thanks for the reply.

Second, I did some research on FSO and FileExists and came up with this code.  The problem is it doesn't quite work, but I think I'm close.  What I'm trying to do is rename a file that is created on a nightly basis.  The software puts identifiers at the end of the file name I've created (Int_Data) that cannot be predicted.  For example "Int_Data_14549640.xls".  So, what I'm trying to do is script something to go out, find a file that begins with Int_Data_*.xls and rename it as simply Int_Data.xls.  Thanks.

Function Interval_Datafile_Name_Change()


   Dim fso
   Dim SourceFile
   Dim DestFile

   Set fso = CreateObject("Scripting.FileSystemObject")

   SourceFile = "C:\Documents and Settings\My Documents\Reporting\Data\Int_Data" & "*"
   DestFile = "C:\Documents and Settings\My Documents\Reporting\Data\Int_Data.xls"
  
       If fso.FileExists(SourceFile) Then
           fso.MoveFile SourceFile, DestFile
     
       End If

   Set fso = Nothing

End Function

(in reply to dm_4ever)
 
 
Post #: 3
 
 RE: Help - 6/20/2008 9:29:49 AM   
  dm_4ever


Posts: 2665
Score: 46
Joined: 6/29/2006
From: Orange County, California
Status: offline
In that case you might be able to do without the FileExists method

(untested)

SourceFile = "C:\Documents and Settings\My Documents\Reporting\Data\Int_Data_*.xls"
DestFile = "C:\Documents and Settings\My Documents\Reporting\Data\Int_Data.xls"

fso.MoveFile SourceFile, DestFile

_____________________________

dm_4ever

My philosophy: K.I.S.S - Keep It Simple Stupid
Read Me: http://www.visualbasicscript.com/m_24727/tm.htm
Frequently Asked Stuff: http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to scot)
 
 
Post #: 4
 
 RE: Help - 6/23/2008 2:20:30 AM   
  scot

 

Posts: 3
Score: 0
Joined: 6/20/2008
Status: offline
Thanks for the reply and the advice, but unfortunately the "*" at the end of the sourcefile string isn't working.  If I use the code to find a "known" file name then it works.  It's the ability to find a file that has the "unknown" name that's hanging me up still.  If you have any more thoughts I'd appreciate it.

(in reply to dm_4ever)
 
 
Post #: 5
 
 RE: Help - 6/23/2008 3:05:51 AM   
  dm_4ever


Posts: 2665
Score: 46
Joined: 6/29/2006
From: Orange County, California
Status: offline
Loop through the files in the directory looking for the file pattern....you can use the InStr function or a regular expression....there are plenty of examples of very similar things being done.

_____________________________

dm_4ever

My philosophy: K.I.S.S - Keep It Simple Stupid
Read Me: http://www.visualbasicscript.com/m_24727/tm.htm
Frequently Asked Stuff: http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to scot)
 
 
Post #: 6
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Help Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts