Hello all,

I need help to rename a file extension using the VBScript. I am
relatively new to this and have put this much together so far:

strComputer = "."
Set objWMIService = GetObject _
("winmgmts:" & "!\\" & strComputer & "\root\cimv2")
Set colFiles = objWMIService.ExecQuery _
("Select * from Cim_Datafile where Name = " _
& "'D:\\test\\test.txt'")
For Each objFile in colFiles
errResult = objFile.Rename("D:\test\test." &
FormatdateTime(Now(),"ddhh")")
Wscript.Echo errResult
Next

I need the file extension to be in the format test.ddhh complete with
the two digit day and hour. Any help is appreciated. Thanks!

JV

Re: Rename file extension by Steven

Steven
Sat Feb 18 15:18:15 CST 2006

I'm curious as to why your using WMI???

http://aspfaq.com/show.asp?id=2074

--
Regards

Steven Burn
Ur I.T. Mate Group
www.it-mate.co.uk

Keeping it FREE!

"Monsignor JAV" <jonvillalva@gmail.com> wrote in message
news:1140224114.980180.226450@f14g2000cwb.googlegroups.com...
> Hello all,
>
> I need help to rename a file extension using the VBScript. I am
> relatively new to this and have put this much together so far:
>
> strComputer = "."
> Set objWMIService = GetObject _
> ("winmgmts:" & "!\\" & strComputer & "\root\cimv2")
> Set colFiles = objWMIService.ExecQuery _
> ("Select * from Cim_Datafile where Name = " _
> & "'D:\\test\\test.txt'")
> For Each objFile in colFiles
> errResult = objFile.Rename("D:\test\test." &
> FormatdateTime(Now(),"ddhh")")
> Wscript.Echo errResult
> Next
>
> I need the file extension to be in the format test.ddhh complete with
> the two digit day and hour. Any help is appreciated. Thanks!
>
> JV
>



Re: Rename file extension by Monsignor

Monsignor
Tue Feb 21 18:40:45 CST 2006

Thanks for sending me the link Steven. I was talking with someone elses
and they also suggested using file system object after I had already
posted. Like I said I am a beginner at this and it was originally
suggested that I use wmi because these scripts are going to be
automated on a server for an access database we have been designing. I
was under the impression that with a wmi script it would enforce a
global policy regardless of what ever else was going on. Anyway. I
looked at the link and this does not clearly explain how to format the
extension with a dynamic "*.ddhh" after each new file is created. The
files will be created every hour or two and have the extension of
*.txt. I need to change these extensions before ftping them with a file
extension in the format

test.format(Now(),"ddhh").

Do you by chance now how to write the script for this. In advance
thanks for your input or help.


Re: Rename file extension by Steven

Steven
Tue Feb 21 22:07:45 CST 2006

I've pre-saved a copy of the script in a .vbs file for you if it will be
easier

http://downloads.mysteryfcm.co.uk/scripts/vbsrenamefileext.vbs

If you'd rather do it yourself, the script is below.

'// START
'// vbsRenameFileExt.vbs
Option Explicit
WScript.Echo "Starting"
RenameFiles ".\" '// ./ is the directory containing this script
WScript.Echo "Finished"
Sub RenameFiles(sFolder)
Dim objFSO, colFiles, objFile, sNewExt
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set colFiles = objFSO.GetFolder(sFolder).Files
For Each objFile In colFiles
sNewExt = "." & Day(Now) & Hour(Now) & Minute(Now)
objFSO.MoveFile objFile, Replace(objFile.Name, ".txt", sNewExt)
Next
End Sub
'// END

--
Regards

Steven Burn
Ur I.T. Mate Group
www.it-mate.co.uk

Keeping it FREE!

"Monsignor JAV" <jonvillalva@gmail.com> wrote in message
news:1140568845.867780.42580@o13g2000cwo.googlegroups.com...
> Thanks for sending me the link Steven. I was talking with someone elses
> and they also suggested using file system object after I had already
> posted. Like I said I am a beginner at this and it was originally
> suggested that I use wmi because these scripts are going to be
> automated on a server for an access database we have been designing. I
> was under the impression that with a wmi script it would enforce a
> global policy regardless of what ever else was going on. Anyway. I
> looked at the link and this does not clearly explain how to format the
> extension with a dynamic "*.ddhh" after each new file is created. The
> files will be created every hour or two and have the extension of
> *.txt. I need to change these extensions before ftping them with a file
> extension in the format
>
> test.format(Now(),"ddhh").
>
> Do you by chance now how to write the script for this. In advance
> thanks for your input or help.
>



Re: Rename file extension by Monsignor

Monsignor
Tue Mar 07 17:42:23 CST 2006

Steve you have been a great help but I have one more question for you.
Is there a way to get the leading zeros in the day-time format for the
extension if they are less than ten? I think this was the one of the
reasons the fella I spoke to told me to use WMI. Please help me this
one last time. Thanks!

Jon V
Steven Burn wrote:
> I've pre-saved a copy of the script in a .vbs file for you if it will be
> easier
>
> http://downloads.mysteryfcm.co.uk/scripts/vbsrenamefileext.vbs
>
> If you'd rather do it yourself, the script is below.
>
> '// START
> '// vbsRenameFileExt.vbs
> Option Explicit
> WScript.Echo "Starting"
> RenameFiles ".\" '// ./ is the directory containing this script
> WScript.Echo "Finished"
> Sub RenameFiles(sFolder)
> Dim objFSO, colFiles, objFile, sNewExt
> Set objFSO = CreateObject("Scripting.FileSystemObject")
> Set colFiles = objFSO.GetFolder(sFolder).Files
> For Each objFile In colFiles
> sNewExt = "." & Day(Now) & Hour(Now) & Minute(Now)
> objFSO.MoveFile objFile, Replace(objFile.Name, ".txt", sNewExt)
> Next
> End Sub
> '// END
>
> --
> Regards
>
> Steven Burn
> Ur I.T. Mate Group
> www.it-mate.co.uk
>
> Keeping it FREE!
>
> "Monsignor JAV" <jonvillalva@gmail.com> wrote in message
> news:1140568845.867780.42580@o13g2000cwo.googlegroups.com...
> > Thanks for sending me the link Steven. I was talking with someone elses
> > and they also suggested using file system object after I had already
> > posted. Like I said I am a beginner at this and it was originally
> > suggested that I use wmi because these scripts are going to be
> > automated on a server for an access database we have been designing. I
> > was under the impression that with a wmi script it would enforce a
> > global policy regardless of what ever else was going on. Anyway. I
> > looked at the link and this does not clearly explain how to format the
> > extension with a dynamic "*.ddhh" after each new file is created. The
> > files will be created every hour or two and have the extension of
> > *.txt. I need to change these extensions before ftping them with a file
> > extension in the format
> >
> > test.format(Now(),"ddhh").
> >
> > Do you by chance now how to write the script for this. In advance
> > thanks for your input or help.
> >


Re: Rename file extension by Monsignor

Monsignor
Tue Mar 07 17:43:05 CST 2006

Steve you have been a great help but I have one more question for you.
Is there a way to get the leading zeros in the day-time format for the
extension if they are less than ten? I think this was the one of the
reasons the fella I spoke to told me to use WMI. Please help me this
one last time. Thanks!

Jon V
Steven Burn wrote:
> I've pre-saved a copy of the script in a .vbs file for you if it will be
> easier
>
> http://downloads.mysteryfcm.co.uk/scripts/vbsrenamefileext.vbs
>
> If you'd rather do it yourself, the script is below.
>
> '// START
> '// vbsRenameFileExt.vbs
> Option Explicit
> WScript.Echo "Starting"
> RenameFiles ".\" '// ./ is the directory containing this script
> WScript.Echo "Finished"
> Sub RenameFiles(sFolder)
> Dim objFSO, colFiles, objFile, sNewExt
> Set objFSO = CreateObject("Scripting.FileSystemObject")
> Set colFiles = objFSO.GetFolder(sFolder).Files
> For Each objFile In colFiles
> sNewExt = "." & Day(Now) & Hour(Now) & Minute(Now)
> objFSO.MoveFile objFile, Replace(objFile.Name, ".txt", sNewExt)
> Next
> End Sub
> '// END
>
> --
> Regards
>
> Steven Burn
> Ur I.T. Mate Group
> www.it-mate.co.uk
>
> Keeping it FREE!
>
> "Monsignor JAV" <jonvillalva@gmail.com> wrote in message
> news:1140568845.867780.42580@o13g2000cwo.googlegroups.com...
> > Thanks for sending me the link Steven. I was talking with someone elses
> > and they also suggested using file system object after I had already
> > posted. Like I said I am a beginner at this and it was originally
> > suggested that I use wmi because these scripts are going to be
> > automated on a server for an access database we have been designing. I
> > was under the impression that with a wmi script it would enforce a
> > global policy regardless of what ever else was going on. Anyway. I
> > looked at the link and this does not clearly explain how to format the
> > extension with a dynamic "*.ddhh" after each new file is created. The
> > files will be created every hour or two and have the extension of
> > *.txt. I need to change these extensions before ftping them with a file
> > extension in the format
> >
> > test.format(Now(),"ddhh").
> >
> > Do you by chance now how to write the script for this. In advance
> > thanks for your input or help.
> >


Re: Rename file extension by Steven

Steven
Tue Mar 07 19:43:56 CST 2006

Change;

sNewExt = "." & Day(Now) & Hour(Now) & Minute(Now)

To;

sDay = Day(Now): If Len(sDay) < 2 Then sDay = "0" & sDay
sNewExt = "." & sDay & Hour(Now) & Minute(Now)

:o)

--
Regards

Steven Burn
Ur I.T. Mate Group
www.it-mate.co.uk

Keeping it FREE!

"Monsignor JAV" <jonvillalva@gmail.com> wrote in message
news:1141774943.109656.131590@i39g2000cwa.googlegroups.com...
> Steve you have been a great help but I have one more question for you.
> Is there a way to get the leading zeros in the day-time format for the
> extension if they are less than ten? I think this was the one of the
> reasons the fella I spoke to told me to use WMI. Please help me this
> one last time. Thanks!
>
> Jon V
> Steven Burn wrote:
> > I've pre-saved a copy of the script in a .vbs file for you if it will be
> > easier
> >
> > http://downloads.mysteryfcm.co.uk/scripts/vbsrenamefileext.vbs
> >
> > If you'd rather do it yourself, the script is below.
> >
> > '// START
> > '// vbsRenameFileExt.vbs
> > Option Explicit
> > WScript.Echo "Starting"
> > RenameFiles ".\" '// ./ is the directory containing this script
> > WScript.Echo "Finished"
> > Sub RenameFiles(sFolder)
> > Dim objFSO, colFiles, objFile, sNewExt
> > Set objFSO = CreateObject("Scripting.FileSystemObject")
> > Set colFiles = objFSO.GetFolder(sFolder).Files
> > For Each objFile In colFiles
> > sNewExt = "." & Day(Now) & Hour(Now) & Minute(Now)
> > objFSO.MoveFile objFile, Replace(objFile.Name, ".txt", sNewExt)
> > Next
> > End Sub
> > '// END
> >
> > --
> > Regards
> >
> > Steven Burn
> > Ur I.T. Mate Group
> > www.it-mate.co.uk
> >
> > Keeping it FREE!
> >
> > "Monsignor JAV" <jonvillalva@gmail.com> wrote in message
> > news:1140568845.867780.42580@o13g2000cwo.googlegroups.com...
> > > Thanks for sending me the link Steven. I was talking with someone
elses
> > > and they also suggested using file system object after I had already
> > > posted. Like I said I am a beginner at this and it was originally
> > > suggested that I use wmi because these scripts are going to be
> > > automated on a server for an access database we have been designing. I
> > > was under the impression that with a wmi script it would enforce a
> > > global policy regardless of what ever else was going on. Anyway. I
> > > looked at the link and this does not clearly explain how to format the
> > > extension with a dynamic "*.ddhh" after each new file is created. The
> > > files will be created every hour or two and have the extension of
> > > *.txt. I need to change these extensions before ftping them with a
file
> > > extension in the format
> > >
> > > test.format(Now(),"ddhh").
> > >
> > > Do you by chance now how to write the script for this. In advance
> > > thanks for your input or help.
> > >
>



Re: Rename file extension by Dr

Dr
Wed Mar 08 11:15:54 CST 2006

JRS: In article <1141774943.109656.131590@i39g2000cwa.googlegroups.com>
, dated Tue, 7 Mar 2006 15:42:23 remote, seen in news:microsoft.public.s
cripting.vbscript, Monsignor JAV <jonvillalva@gmail.com> posted :

>Is there a way to get the leading zeros in the day-time format for the
>extension if they are less than ten?

Please do not over-quote or top-post.

>> sNewExt = "." & Day(Now) & Hour(Now) & Minute(Now)

That's silly, as 11111 could mean the 11th at 01:11 or 11:01, or 11:11
on the 1st. See <URL:http://www.merlyn.demon.co.uk/datefmts.htm#NLZ>.

sNewExt = "." & (Day(Now)*10000 + Hour(Now)*100 + Minute(Now))

But don't call Now more than once; it can change.

N = Now
sNewExt = "." & (Day(N)*10000 + Hour(N)*100 + Minute(N))

To include a leading zero on the Day

sNewExt = "." & _
Right(1000000 + Day(N)*10000 + Hour(N)*100 + Minute(N), 6)


See <URL:http://www.merlyn.demon.co.uk/vb-dates.htm>.

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
<URL:http://www.jibbering.com/faq/> JL/RC: FAQ of news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.

Re: Rename file extension by Dr

Dr
Wed Mar 08 12:55:56 CST 2006

JRS: In article <#C7rsGlQGHA.2536@tk2msftngp13.phx.gbl>, dated Wed, 8
Mar 2006 01:43:56 remote, seen in news:microsoft.public.scripting.vbscri
pt, Steven Burn <somewhere@in-time.invalid> posted :
>Change;
>
>sNewExt = "." & Day(Now) & Hour(Now) & Minute(Now)
>
>To;
>
>sDay = Day(Now): If Len(sDay) < 2 Then sDay = "0" & sDay
>sNewExt = "." & sDay & Hour(Now) & Minute(Now)

Please limit your quoting, as is customary in Usenet.

Your suggestion is inadequate. Leading zeroes are necessary on Hour and
Minute, to avoid ambiguity, and are inessential though recommended for
Day. See the pages previously cited.

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 MIME. ©
Web <URL:http://www.merlyn.demon.co.uk/> - w. FAQish topics, links, acronyms
PAS EXE etc : <URL:http://www.merlyn.demon.co.uk/programs/> - see 00index.htm
Dates - miscdate.htm moredate.htm js-dates.htm pas-time.htm critdate.htm etc.

Re: Rename file extension by Steven

Steven
Wed Mar 08 18:27:06 CST 2006

Was only meant to be an example ;o)

--
Regards

Steven Burn
Ur I.T. Mate Group
www.it-mate.co.uk

Keeping it FREE!

"Dr John Stockton" <jrs@merlyn.demon.co.uk> wrote in message
news:iKmU+DH8iyDEFwXT@merlyn.demon.co.uk...
> JRS: In article <#C7rsGlQGHA.2536@tk2msftngp13.phx.gbl>, dated Wed, 8
> Mar 2006 01:43:56 remote, seen in news:microsoft.public.scripting.vbscri
> pt, Steven Burn <somewhere@in-time.invalid> posted :
> >Change;
> >
> >sNewExt = "." & Day(Now) & Hour(Now) & Minute(Now)
> >
> >To;
> >
> >sDay = Day(Now): If Len(sDay) < 2 Then sDay = "0" & sDay
> >sNewExt = "." & sDay & Hour(Now) & Minute(Now)
>
> Please limit your quoting, as is customary in Usenet.
>
> Your suggestion is inadequate. Leading zeroes are necessary on Hour and
> Minute, to avoid ambiguity, and are inessential though recommended for
> Day. See the pages previously cited.
>
> --
> © John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00
MIME. ©
> Web <URL:http://www.merlyn.demon.co.uk/> - w. FAQish topics, links,
acronyms
> PAS EXE etc : <URL:http://www.merlyn.demon.co.uk/programs/> - see
00index.htm
> Dates - miscdate.htm moredate.htm js-dates.htm pas-time.htm critdate.htm
etc.