Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- fmt = "mdy" 'code for default date format
- sub help
- wsh.echo "Usage:" & vblf & vblf & _
- "Append file date to given file:" & vblf & _
- " AppendFileDateToFileName [option] {file...}" & vblf & vblf & _
- "Add to context menu:" & vblf & _
- " AppendFileDateToFileName /addmenu" & vblf & vblf & _
- "Remove from context menu:" & vblf & _
- " AppendFileDateToFileName /delmenu" & vblf & vblf & _
- "Option:" & vblf & vblf & _
- "/mdy" & vbtab & "Use mm-dd-yyyy format (default)." & vblf & _
- "/ymd" & vbtab & "Use yyyy-mm-dd format." & vblf & _
- "/dmy" & vbtab & "Use dd-mm-yyyy format."
- wsh.quit
- end sub
- function zerolead(s)
- zerolead = right("0" & s, 2)
- end function
- if wsh.arguments.count = 0 then help
- set fs = createobject("scripting.filesystemobject")
- set ws = createobject("wscript.shell")
- on error resume next
- if wsh.arguments.named.exists("addmenu") then
- ws.regwrite "HKCR\*\shell\AppendFileDateToFileName\", _
- "Append file date to file name"
- if err.number = 0 then
- ws.regwrite "HKCR\*\shell\AppendFileDateToFileName\command\", _
- "wscript.exe """ & wsh.scriptfullname & """ ""%1"""
- end if
- if err.number <> 0 then wsh.echo err.description
- wsh.quit
- elseif wsh.arguments.named.exists("delmenu") then
- ws.regdelete "HKCR\*\shell\AppendFileDateToFileName\command\"
- ws.regdelete "HKCR\*\shell\AppendFileDateToFileName\"
- if err.number <> 0 then wsh.echo err.description
- wsh.quit
- end if
- if wsh.arguments.unnamed.count = 0 then help
- if wsh.arguments.named.exists("mdy") then
- fmt = "mdy"
- elseif wsh.arguments.named.exists("ymd") then
- fmt = "ymd"
- elseif wsh.arguments.named.exists("dmy") then
- fmt = "dmy"
- end if
- for each fn in wsh.arguments.unnamed
- if fs.fileexists(fn) then
- set f = fs.getfile(fn)
- select case fmt
- case "mdy"
- s = zerolead(datepart("m", f.datelastmodified)) & "-" & _
- zerolead(datepart("d", f.datelastmodified)) & "-" & _
- datepart("yyyy", f.datelastmodified)
- case "ymd"
- s = datepart("yyyy", f.datelastmodified) & "-" & _
- zerolead(datepart("m", f.datelastmodified)) & "-" & _
- zerolead(datepart("d", f.datelastmodified))
- case "dmy"
- s = zerolead(datepart("d", f.datelastmodified)) & "-" & _
- zerolead(datepart("m", f.datelastmodified)) & "-" & _
- datepart("yyyy", f.datelastmodified)
- end select
- i = instrrev(f.name, ".")
- if i > 0 then
- n = left(f.name, i - 1)
- e = mid(f.name, i)
- else
- n = f.name
- e = ""
- end if
- err.clear
- f.name = n & " " & s & e
- if err.number <> 0 then wsh.echo err.description & ": " & f.path
- else
- wsh.echo "Not found: " & fn
- end if
- next
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement