Jump to content
Sign in to follow this  
Diana (Cda)

Renaming files - lingering issue with day of week ...

Recommended Posts

Diana (Cda)

Hi, everyone!

I have a lingering file renaming issues or two. This one deals with a missing day of the week. The files have this date in their filenames:





Is there any way to get AI to rename them but by adding the day of the week, so that the above examples become this?:





To do this manually, I've used Rover's script (from here:)

;  Rover's script:  http://www.autoitscript.com/forum/topic/124981-resolved-yeay-fix-to-personal-day-format-usually-works/
#include <Date.au3>
#include <DateTimeConstants.au3>
#include <GUIConstantsEx.au3>
;#include<_My_DATE.au3>     ; my date, time conventions, etc.
#include <WindowsConstants.au3>

Global $GUIboxTitle  = "Date Picker:"
Global $DateFormat   = "yyyy.MM.dd.ddd"
;$Button1_Text         = "Create folder and send date to clipboard ..."
$Button1_Text         = "Send date to the clipboard ..."
; where text is not needed in either Prefix or Suffix - i.e., before or after the date - then just leave blank by using "" (no text in between quotes).
$DateNameText_PREFIX  = ""
$DateNameText_SUFFIX  = "- "

Global $sPath         = "", $sDateParams
Global $hGUI = GUICreate($GUIboxTitle, 325, 250, 325, 340)     ; width, height, left, top (this determines size of entire GUI box)

Global $date = GUICtrlCreateDate("", 10, 10, 200, 20)     ; calendar pulldown box
GUICtrlSendMsg($date, 0x1032, 0, $DateFormat) ; $DTM_SETFORMAT

Global $hLabel1 = GUICtrlCreateLabel("", 10,  50, 300, 20)
Global $hLabel2 = GUICtrlCreateLabel("", 10,  80, 300, 20)
Global $hLabel3 = GUICtrlCreateLabel("", 10, 110, 300, 20)
Global $hLabel4 = GUICtrlCreateLabel("", 10, 140, 300, 20)

;Global $DateChooseButton = GUICtrlCreateButton("Create folder and send date to clipboard ...", 10, 200, 250, 30)
;Global $DateChooseButton = GUICtrlCreateButton("Create folder here (also sends date to clipboard) ...", 10, 200, 300, 30)     ; left, top, width, height (location of button)
Global $DateChooseButton = GUICtrlCreateButton($Button1_Text, 10, 200, 300, 30)     ; left, top, width, height (location of button)

;Global $FolderChooseButton = GUICtrlCreateButton("Select folder", 10, 170, 250, 30)
;Global $FolderChooseButton = GUICtrlCreateButton("1.  Select folder ...", 10, 170, 450, 30)

$sDateParams = _GetDate($date, $hLabel1)

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
;       Case $FolderChooseButton
;            $sPath = FileSelectFolder("Select folder", "" , 7 , @DesktopDir, $hGUI)
;            GUICtrlSetData($FolderChooseButton, "1.  Path selected:  ''" & $sPath & "''")
        Case $DateChooseButton
            $ChosenDateFormat = $DateNameText_PREFIX & $sDateParams & $DateNameText_SUFFIX
;           $sDateParams = _GetDate($date, $hLabel1)
;           ClipPut($sDateParams)
;           If FileExists($sPath) = 1 Then
;               FileChangeDir($sPath)
;               DirCreate(@ScriptDir & "\" & $ChosenDateFormat)
;           EndIf


Func _GetDate($cDate, $clabel)
    Local $parametersDate = GUICtrlRead($cDate)

    ;use StringRight() to get the three character weekday abbrev. from the selected date.
    Local $sWkDay = StringRight($parametersDate, 3)

    ;get the two character weekday abbreviation from the three-character weekday abbreviation.
    Local $ShortDayMyFormat = StringMid("Sn,Mn,Tu,Wd,Th,Fr,Sa", StringInStr("SunMonTueWedThuFriSat", $sWkDay), 2)

    ;replace the three character weekday, with the two character weekday.
    $parametersDate = StringReplace($parametersDate, $sWkDay, $ShortDayMyFormat)
    GUICtrlSetData($clabel, "Chosen date above, formatted as:  " & $parametersDate)
    Return $parametersDate

Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
    #forceref $hWnd, $iMsg, $iwParam
    Local $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
    Switch DllStructGetData($tNMHDR, "IDFrom")
        Case $date
            Switch DllStructGetData($tNMHDR, "Code")
                Case $DTN_DATETIMECHANGE ; Sent by a date and time picker (DTP) control whenever a change occurs
                    $sDateParams = _GetDate($date, $hLabel1)
                    Return 0
EndFunc   ;==>WM_NOTIFY

which sends the date format to the clipboard. But since I'm an old time radio fan junkie and I listen to OTR streaming radio every day, I have quite a few files to rename when I get around to doing that 2 or 3 times a week. And it's still a pain even with all the shortcuts I use via a renaming utility that utilizes regex and everything.

Is there a way to get AI to rename these files so that it adds the day of week to the name automatically rather than my doing it manually?

I've searched in last few months more regex renaming apps but nothing so far does what's needed (esp. with my custom 2-character day of week format - Sn instead of Sun, etc.).


(p.s., there should be a way to do this, Kylomas' approach shows that something like this is possible via even FileCopy - )

Edited by Diana (Cda)

Share this post

Link to post
Share on other sites

Fro helpfile

#include <Date.au3>

$strdate = "1945.06.10"
$astrdate = StringSplit($strdate,".",3)

; Week day number for a given date
$iWeekday = _DateToDayOfWeek ($astrdate[0], $astrdate[1], $astrdate[2])
; Should be equal to @Wday
;MsgBox(4096, "", "Todays WeekdayNumber is: " & $iWeekDay)
MsgBox(4096, "", "Filename = " & $astrdate[0] & ":" & $astrdate[1] & ":" & $astrdate[2] & " " & _DateDayOfWeek($iWeekDay))

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Share this post

Link to post
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
Sign in to follow this  


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.