Page 1 of 1
RENAME FILES WITH DATES/TIMES
#1
Posted 27 December 2007 - 01:22 PM
I have mostly worked with scripts using Unix shells and am struggling to do what is a simple job in Unix scripts but somehow I can't get it in windows scripts....
What I basically need to do is execute a script that will rename all files in a directory and add a date-time stamp to the file name and add a file extension...
All files in the directory will not have a file extension....
In unix it would be an easy for each loop using variables...
an example I'd like would be something like the following....
file1
file2
file3
should turn into
file120071227141820.seq
file220071227141821.seq
file320071227141821.seq
where the datetime stamp is yymmddhhmmss
The 3 files above would be in a directory and the filenames could vary
I guess vb script would be the best and or easiest but anything that works....
Thanks in advance for any guidence.....
What I basically need to do is execute a script that will rename all files in a directory and add a date-time stamp to the file name and add a file extension...
All files in the directory will not have a file extension....
In unix it would be an easy for each loop using variables...
an example I'd like would be something like the following....
file1
file2
file3
should turn into
file120071227141820.seq
file220071227141821.seq
file320071227141821.seq
where the datetime stamp is yymmddhhmmss
The 3 files above would be in a directory and the filenames could vary
I guess vb script would be the best and or easiest but anything that works....
Thanks in advance for any guidence.....
#4
Posted 27 December 2007 - 03:07 PM
Try something like this:
strFolder = "c:\mypath\mydir"
Set objFSO = CreateObject("Scripting.FileSystemObject")
N = Now
strStamp = (((( Year(N)*100 + Month(N))*100 + Day(N))*100 + _
Hour(N)) * 100 + Minute(N))*100 + Second(N)
Set objFolder = objFSO.GetFolder(strFolder)
Set objFiles = objFolder.Files
For Each objFile In objFiles
objFSO.MoveFile objFile.path , objFile.parentfolder & "\" &_
objFile.name & strStamp
NextChange the strFolder data accordingly!
#5
Posted 27 December 2007 - 05:22 PM
Here is another script that will do what you want.
All you have to do is drag and drop a folder on
to the script.
Save As RenameFolder.vbs
All you have to do is drag and drop a folder on
to the script.
Save As RenameFolder.vbs
Quote
Dim Act :Set Act = CreateObject("Wscript.Shell")
Dim Fso :Set Fso = CreateObject("Scripting.FileSystemObject")
Dim F1, F2, F3, F4, StrS
'/-> Time Stamp
Function TimeStamp()
StrS = _
Year(Date) & _
Month(Date) & _
Day(Date) & _
Hour(Time) & _
Minute(Time) & _
Second(Time)
End Function
'/-> Checks To See If Some Thing Is Drag And Drop On To The Script
If WScript.Arguments.Count = 0 Then
Act.Popup "This script needs a folder to be drag " & vbCrLf &_
"and drop on this file to start.",30,"Error No Source", 4128
WScript.Quit()
Else
For Each F1 in Wscript.Arguments
'/-> Check To See If It A File Or Folder
If Right(InStr(F1,"."),4) Then
Act.Popup "This Is A File, Cannot Continue",7,"Not A Folder",4128
Exit For
Else
'/-> Start A Collection Of The Files Inside Of The Folder
Set F2 = Fso.GetFolder(F1)
For Each F3 in F2.Files
'/-> Break Up The File Name
F4 = Split(F3.Name,".")
TimeStamp()
Fso.MoveFile F3.Path, F2.Path & "\" & F4(0) & StrS & "." & F4(1)
Next
End If
Next
End If
#6
Posted 27 December 2007 - 10:02 PM
gunsmokingman, on Dec 27 2007, 06:22 PM, said:
Dim Fso :Set Fso = CreateObject("Scripting.FileSystemObject")
Dim F1, F2, F3, F4, StrS
Dim F1, F2, F3, F4, StrS
gunsmokingman,
I just would like to know if there is a reason why you always use DIM when there is no data types in VBScripts. IMHO, they are useless but why you use them anyway ?
This post has been edited by jdoe: 27 December 2007 - 10:05 PM
#7
Posted 28 December 2007 - 01:22 AM
jdoe, on Dec 28 2007, 06:02 AM, said:
gunsmokingman, on Dec 27 2007, 06:22 PM, said:
Dim Fso :Set Fso = CreateObject("Scripting.FileSystemObject")
Dim F1, F2, F3, F4, StrS
Dim F1, F2, F3, F4, StrS
gunsmokingman,
I just would like to know if there is a reason why you always use DIM when there is no data types in VBScripts. IMHO, they are useless but why you use them anyway ?
It consider good scripting, from all I have read.
#8
Posted 29 December 2007 - 11:37 PM
Yzöwl, on Dec 27 2007, 04:07 PM, said:
Try something like this:
strFolder = "c:\mypath\mydir"
Set objFSO = CreateObject("Scripting.FileSystemObject")
N = Now
strStamp = (((( Year(N)*100 + Month(N))*100 + Day(N))*100 + _
Hour(N)) * 100 + Minute(N))*100 + Second(N)
Set objFolder = objFSO.GetFolder(strFolder)
Set objFiles = objFolder.Files
For Each objFile In objFiles
objFSO.MoveFile objFile.path , objFile.parentfolder & "\" &_
objFile.name & strStamp
NextChange the strFolder data accordingly!Thank you very much for this code... it did the trick for me....
Happy New Year.....
Page 1 of 1

Sign In
Register
Help

MultiQuote



Report
