Jump to content

Rename File Based on Date


Recommended Posts


Here is a VBS script that uses the move function to rename the file and add Day-Month-Year_ToFile.ext.

'-> This code is property of Gunsmokingman and Or Jake1Eye and you must have his permission to use.'-> This is only posted as example code and meant only to used as such.'-> Handles Drag Drop Or Cmd Line Argument  Select Case WScript.Arguments.Count   Case 0    MsgBox vbTab & "Error No File" & vbCrLf & _          "You Must Drag And Drop One File On To" & vbCrLf & _          "This Script To Be Able Use This Script.",4128,"Error No File"  Case 1   Dim Fso :Set Fso = CreateObject("Scripting.FileSystemObject")   Dim Arg, Dy, Mh, NewFile, Yr   Dy = Day(Now) :Mh =Month(Now) :Yr = Year(Now)'-> Add Zero Day And Month If Needed EG 1 = 01   If Len(Dy) = 1 Then Dy = "0" & Dy    If Len(Mh) = 1 Then Mh = "0" & Mh   Set Arg = Fso.GetFile(WScript.Arguments.Item(0))   NewFile = Fso.GetParentFolderName(Arg.Path) & "\" & Dy & "-" & Mh & "-" & Yr & "_" & Arg.Name   If Not Fso.FileExists(NewFile) Then Fso.MoveFile WScript.Arguments.Item(0), NewFile  Case Else   MsgBox vbTab & "Error Exceeds One File" & vbCrLf & _          "This Script Requires Only One File To Be" & vbCrLf & _          "Drag And Drop. Files Drag And Drop Total : " & WScript.Arguments.Count _          ,4128,"Error To Many Files"  End Select 
I tested the script using this cmd prompt script, I made sure both paths had an space in either path. I did not try the script with any special characters.

@Echo OffCLSCOLOR F9Mode 75,7Echo.Echo Processing D:\boot.wimSet A1="C:\Users\Gunsmokingman\Desktop\Test One\DragDropAddDateForNewName.vbs"Set A2="D:\Test Folder\boot.wim"start "" /w %A1% %A2%pause
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...