Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


I need to rename a file adding a "."dot before the YYYY (between the letter "S" and "2008")

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

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> I need to rename a file adding a "."dot before the YYYY (between the letter "S" and "2008")
  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 >>
 I need to rename a file adding a "."dot befor... - 1/9/2008 8:54:14 AM   
  webtecnic

 

Posts: 2
Score: 0
Joined: 1/9/2008
Status: offline
I need to rename a file adding a "."dot before the YYYY(Ex: 2008)
 
Step 1 

Before : IF232PMSYYYYMMDDHHMMSS.V     
After:    IF232PMS.YYYYMMDDHHMMSS.DAT

Action: read files(more than one) with IF232PMS*.V and rename them adding "."(dot) before the data and changing the extension from "V" to "DAT".

Step 2

Before : IF242PMS.AAAAMMDDHHMMSS.DAT
After : IF242PMSAAAAMMDDHHMMSS.INI  and  IF242PMSAAAAMMDDHHMMSS.OKI

Action: Read the files with IF232PMS*.DAT and rename them deleting the "."(dot) before the data and changinf the extension from "DAT" to "INI" and creating a backup with ".ORI"

-----
Please..somebody help me...

My script is this at the moment:

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colMonitoredEvents = objWMIService.ExecNotificationQuery _
("SELECT * FROM __InstanceCreationEvent WITHIN 10 WHERE " _
& "Targetinstance ISA 'CIM_DirectoryContainsFile' AND " _
& "TargetInstance.GroupComponent= " _
& "'Win32_Directory.Name=""c:\\\\teste\destino""'")
Do
'Set objLatestEvent = colMonitoredEvents.NextEvent
'Wscript.Echo objLatestEvent.TargetInstance.PartComponent
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set FileList = objWMIService.ExecQuery _
("ASSOCIATORS OF {Win32_Directory.Name='c:\teste\destino'} Where " _
& "ResultClass = CIM_DataFile")
For Each objFile In FileList
If objFile.Extension = "V" Then
strNewName = objFile.Drive & objFile.Path & _
objFile.FileName & "." & "dat"
errResult = objFile.Rename(strNewName)
End If
Next
Loop
 
 
Post #: 1
 
 RE: I need to rename a file adding a "."dot b... - 1/9/2008 9:04:29 AM   
  ebgreen


Posts: 4972
Score: 31
Joined: 7/12/2005
Status: offline
As an example:

strOldName = "IF232PMSYYYYMMDDHHMMSS.V"

strNewName = Left(strOldName, 8) & "." & Mid(strOldName, 9, 14) & ".dat"
WScript.Echo strNewName


_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to webtecnic)
 
 
Post #: 2
 
 RE: I need to rename a file adding a "."dot b... - 1/9/2008 10:32:38 AM   
  Fredledingue


Posts: 383
Score: 0
Joined: 5/9/2005
From:
Status: offline
Another example:
 
strOldName = "IF232PMSYYYYMMDDHHMMSS.V"
strNewName = Replace(Replace(strOldName, "YYYY" ,".YYYY"), ".V", ".DAT")
 
Decide yourself wether it's better to modify a certain patern (like "YYYY") as in my example or to modify/insert characters at a certain position as in ebgreen's exa;ple.



_____________________________

Fred

(in reply to ebgreen)
 
 
Post #: 3
 
 
 
  

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 >> I need to rename a file adding a "."dot before the YYYY (between the letter "S" and "2008") 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