Sign in to follow this  
Followers 0
Diana (Cda)

[RESOLVED] FileMove - take date and time stamp of file in renaming files with AI?

13 posts in this topic

#1 ·  Posted (edited)

In a folder with variations of untitled.mp3, untitled[1].mp3, need to rename adding the date and time stamp to the filename.

I know that something like this:

FileMove(@ScriptDir & "\*.mp3", @ScriptDir & "MP3file- " & ... [date & time] ... & ".mp3", 8)

should more or less do the trick of renaming (with tweaking, I'm going by memory so might not have syntax quite right; I'll fix later). But how could we add the file's date and time stamp in the [date & time] block above?

Thanks!

:)

Edited by Diana (Cda)

Share this post


Link to post
Share on other sites



Diana,

Your situation is similar to the last time you wanted to rename files () only this time you will be running filegettime() inside the filefindfirstfile()...filefindnextfile() loop.

Thanks,

kylomas


Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites

Diana,

Your situation is similar to the last time you wanted to rename files () only this time you will be running filegettime() inside the filefindfirstfile()...filefindnextfile() loop.

Thanks,

kylomas

<sigh> Ah, crap. Okay. Thanks much. Appreciate the tip.

That particular thread I ended up having to go with a non-AI solution. In this case, unless there's a regex way, the freeware that I found that works perfectly for that renaming task won't work in this case. So I'm back to the drawing board to look for some other freeware that might. Too bad that I won't at this time again be able to find an AI solution. This has got too many complicated parts for me to figure out without some sort of example and there wasn't one when I searched. Mind you, with the new forum, the search function isn't as good as before and most of the time I end up googling the forum instead. But I still didn't find anything again.

Well, shelving this one for some time down the road. It's beyond me at this stage.

But thanks. I'll report back if I find a non-AI solution.

:)

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

this time you will be running filegettime() inside the filefindfirstfile()...filefindnextfile() loop.

Well, these backup needs, etc., sure are time-consuming to find solutions for <g>. I found another freeware that will do the job but in this case, the solution has several steps and just isn't worth the bother. Yes, I get the desired end result but unlike other cases, I'd almost do it in the same time to type things up manually so it doesn't make sense to use it. I've returned to trying with AI. Without getting into the loop issue, I'm concentrating on the rename part of these news MP3 files first. Here's what I have so far:

;================================================
$files       = @scriptdir & "\*untitled*.mp3"
$time        =  FileGetTime($files,0)
;------------------------------------------------
$targetfiles = "Rad, CBC1- "
;================================================


If Not @ERROR THEN
;    $filedate = $time[0] & "." & $time[1] & "." & $time[2] & "., " & $time[3] & "h" & $time[4] & "m" & $time[5] & "s"
    $filedate = $time[0] & $time[1] & $time[2] & "., " & $time[3] & "h" & $time[4] & "m" & $time[5] & "s"
    FileCopy($files, $targetfiles & $filedate & ".mp3", 0)
    MsgBox(0,"Modification date of file:",$filedate)
EndIf

The above gives me this type of output where the date part isn't quite right:

Rad, CBC1- 20110201., 19h45m41s.mp3

I need to get this for the date part:

Rad, CBC1- 110201.Tu, 19h45m41s.mp3

But the array gives only 4 digit year:

The array is a single dimension array containing six elements:
$array[0] = year (four digits)
$array[1] = month (range 01 - 12)
$array[2] = day (range 01 - 31)
$array[3] = hour (range 00 - 23)
$array[4] = min (range 00 - 59)
$array[5] = sec (range 00 - 59)
Notice that return values are zero-padded.

There doesn't seem to be anything for a 2-digit year.

Before I have to tackle the problem of cycling through the rest of the mp3 files, is there a way to,

1. get a 2-digit year

2. a custom format day where Mon=Mn, Tue=Tu, Wed=Wd, Thu=Th, Fri=Fr, Sat=Sa, Sun=Sn?

Thanks. If there's no way then there's no reason to pursue this. But as recent experience has shown in another thread, intercepting AI's output and substituting it with custom format output seems to do the job in this type of case.

Thanks! :)

Edited by Diana (Cda)

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Diana,

Try $2Dyr = stringright($time[0]),2) and use $2Dyr where you are currently using $time[0].

Don't you need to process these in a loop for multiple files?

kylomas

Edited by kylomas

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

Hi, thanks!

I got an incorrect number of parameters in function call error and found that it needed to be ($time[0],2) instead of ($time[0]),2). Kewl. So did that little bit of cleanup and the script works just fine now in that part of the date. That is a neat trick to know!

Is there any way to get the days of the week somehow, though? Even just concentrating on getting format Mon, Tue, Wed, Thu, Fri, Sat and Sun as the first step would be good to know if possible. The "array" part of the FileGetTime talks only about number style of formats (??).

Don't you need to process these in a loop for multiple files?

Yes, that's why I wrote above "Without getting into the loop issue, I'm concentrating on the rename part of these news MP3 files first." <g>. I'm breaking this down into hopefully more chewable parts since I needed to see first if I could figure out how to do the renaming part. If I couldn't get past that, the looping part wasn't worth the bother to try to figure out <g>.

Cheers,

:)

Edited by Diana (Cda)

Share this post


Link to post
Share on other sites

Diana,

Sorry about the parentheses error, not enough coffee yet.

Something like this (untested) will give you your date format:

; Week day number for a given date
$iWeekday = _DateToDayOfWeek ($time[0], $time[1], $time[2])

switch $iWeekday
    case 1
        $iweekday = 'Su'
    case 2
        $iweekday = 'Mo'
    case 3
        $iweekday = 'Tu'
    case 4
        $iweekday = 'We'
    case 5
        $iweekday = 'Th'
    case 6
        $iweekday = 'Fr'
    case 7
        $iweekday = 'Sa'
    case Else
        msgbox(0,'','Error in date format.  $iweekday = ' & $iweekday)
EndSwitch

kylomas


Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites

Diana,

This should get you started.

#include <Date.au3>
#include <array.au3>
;================================================
$targetfiles = "Rad, CBC1- "
;================================================

local $files,$file

$files = filefindfirstfile(@scriptdir & "\*untitled*.mp3")

if $files = -1 then
    msgbox(0,'','No files found')
    Exit
endif

while 1

    $file = filefindnextfile($files)
    if @error then exitloop

    ;c(@scriptdir & '\' & $file)

    $time  =  FileGetTime(@scriptdir & '\' & $file,0)
    if @error = 1 then
        msgbox(0,'','Bad return from filegettime')
        Exit
    endif

    $filedate = $time[0] & $time[1] & $time[2] & "., " & $time[3] & "h" & $time[4] & "m" & $time[5] & "s"
    FileCopy($files, $targetfiles & $filedate & ".mp3", 0)
    MsgBox(0,"Modification date of file:",$filedate)

    ; Week day number for a given date
    $iWeekday = _DateToDayOfWeek ($time[0], $time[1], $time[2])

    switch $iWeekday
        case 1
            $iweekday = 'Su'
        case 2
            $iweekday = 'Mo'
        case 3
            $iweekday = 'Tu'
        case 4
            $iweekday = 'We'
        case 5
            $iweekday = 'Th'
        case 6
            $iweekday = 'Fr'
        case 7
            $iweekday = 'Sa'
        case Else
            msgbox(0,'','Error in date format.  $iweekday = ' & $iweekday)
    EndSwitch

wend


func c($str)
    consolewrite('>> ' & $str & @lf)
endfunc

kylomas


Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

Diana,

Rearranged the code and added changes. (got bored) I think this is pretty much what you wanted to do.

;
;
;
#include <Date.au3>
#include <array.au3>
;================================================
$targetfiles = "Rad, CBC1- "
;================================================

local $files,$file

$files = filefindfirstfile(@scriptdir & "\*untitled*.mp3")

if $files = -1 then
    msgbox(0,'','No files found')
    Exit
endif

while 1

    $file = filefindnextfile($files)
    if @error then exitloop

    ;c(@scriptdir & '\' & $file)

    $time  =  FileGetTime(@scriptdir & '\' & $file,0)
    if @error = 1 then
        msgbox(0,'','Bad return from filegettime')
        Exit
    endif

    $iWeekday = _DateToDayOfWeek ($time[0], $time[1], $time[2])
    switch $iWeekday
        case 1
            $iweekday = 'Su'
        case 2
            $iweekday = 'Mo'
        case 3
            $iweekday = 'Tu'
        case 4
            $iweekday = 'We'
        case 5
            $iweekday = 'Th'
        case 6
            $iweekday = 'Fr'
        case 7
            $iweekday = 'Sa'
        case Else
            msgbox(0,'','Error in date format.  $iweekday = ' & $iweekday)
    EndSwitch

    $filedate = stringright($time[0],2) & $time[1] & $time[2] & "." & $iweekday & ", " & $time[3] & "h" & $time[4] & "m" & $time[5] & "s"
    FileCopy($file, $targetfiles & $filedate & ".mp3", 0)
    MsgBox(0,"Modification date of file:",$filedate)

wend


func c($str)
    consolewrite('>> ' & $str & @lf)
endfunc

kylomas

Edit: changed $files to $file

Edit2: ? Your use of the symbol $targetfiles leads me to believe that you may have more than 1 renaming pattern. What was your intent for this variable?

Edited by kylomas

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites

Diana,

This thread may interest you -

kylomas


Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites

kylomas

Edit: changed $files to $file

Edit2: ? Your use of the symbol $targetfiles leads me to believe that you may have more than 1 renaming pattern. What was your intent for this variable?

Hi, Kylomas!

You produce amazing stuff when you're bored! <g>

Sorry for the great delay in getting back to you. Lots of RL stuff happening; finished a job, running around interviewing for a second contract and started a doozy of a contract this week. Though the pay is the absolute pits, lots to put on my resumé when it's over. But all this took a lot out of my "spare" time <g>.

This second script did the job. I ended up with these file copies below. I record the news station of a local streaming radio and like to keep for future reference:

Rad, CBC1- 110303.Th, 08h35m49s.mp3

Rad, CBC1- 110217.Th, 08h11m34s.mp3

Rad, CBC1- 110217.Th, 17h10m14s.mp3

Rad, CBC1- 110218.Fr, 07h55m09s.mp3

Rad, CBC1- 110222.Tu, 07h45m26s.mp3

Rad, CBC1- 110223.We, 07h50m16s.mp3

Rad, CBC1- 110224.Th, 09h00m27s.mp3

Rad, CBC1- 110225.Fr, 07h54m50s.mp3

Rad, CBC1- 110302.We, 10h12m30s.mp3

Rad, CBC1- 110304.Fr, 02h13m25s.mp3

Rad, CBC1- 110304.Fr, 08h36m14s.mp3

The file names _all_ all checked out with their time and date stamps so this is awesome.

Re file renaming patterns, when considering dates and times, I actually only have 2 date styles and 2 time styles, depending on need. The above has always the same file naming convention that the short date format is best - less characters mean shorter total filepath so since these nested a little deeply, shorter path good here. But left seconds in filename in case there is the occasional time when I start and stop the recording of my streaming radio app within same minute.

This is amazing. I'm going to continue studying this code. There are a few bits of syntax that I haven't worked with before so it really helps to see them in a real life situation to see how they fit in with other code.

Cheers!

:)

Share this post


Link to post
Share on other sites

Diana,

This thread may interest you -

kylomas

Thanks! I will study the information there.

Share this post


Link to post
Share on other sites

Hi, there!

I ended up doing my usual finalizing of the script to a bit of a standard format that I use. I've tested this several times and, so far, it works a treat! In terms of actual code, I really only had to tweak the short day format and just felt need to add a splash screen to block user a little bit - always handy when computer should be left do its thing a bit without potentially interfering with the process by typing and mouse clicking while working in other processes <g>.

;
; AutoIt 3x
;
#include <Date.au3>
#include <array.au3>
#NoTrayIcon     ; AutoIt's icon doesn't show in systray
TraySetIcon("Shell32.dll", 147)     ; changes the icon displayed in the systray
AutoItSetOption("WinTitleMatchMode", 2)     ; this allows partial window titles to be valid!
;-------------------------------------------------------------------------------------------------------------------------


_SplashTextON()     ; Make sure a "_SplashOff()" is at end to turn off the splash screen


;================================================
$targetfiles = "Rad, CBC1- "
;================================================


local $files,$file

$files = filefindfirstfile(@scriptdir & "\*untitled*.mp3")

if $files = -1 then
    msgbox(0,'','No files found')
    Exit
endif

while 1

    $file = filefindnextfile($files)
    if @error then exitloop

    ;c(@scriptdir & '\' & $file)

    $time  =  FileGetTime(@scriptdir & '\' & $file,0)
    if @error = 1 then
        msgbox(0,'','Bad return from filegettime')
        Exit
    endif

    $iWeekday = _DateToDayOfWeek ($time[0], $time[1], $time[2])
    switch $iWeekday
        case 1
            $iweekday = 'Sn'
        case 2
            $iweekday = 'Mn'
        case 3
            $iweekday = 'Tu'
        case 4
            $iweekday = 'Wd'
        case 5
            $iweekday = 'Th'
        case 6
            $iweekday = 'Fr'
        case 7
            $iweekday = 'Sa'
        case Else
            msgbox(0,'','Error in date format.  $iweekday = ' & $iweekday)
    EndSwitch

    $filedate = stringright($time[0],2) & $time[1] & $time[2] & "." & $iweekday & ", " & $time[3] & "h" & $time[4] & "m" & $time[5] & "s"
    FileCopy($file, $targetfiles & $filedate & " (needsTrimming).mp3", 0)
    ;MsgBox(0,"Modification date of file:",$filedate)

wend




_SplashTextOFF()     ;  turns off Splash...On(...) above.




Func c($str)
    consolewrite('>> ' & $str & @lf)
Endfunc
;--------------------------------------------------------------------------------------------------
Func _SplashTextON()
    Beep(1000, 50)
    Beep(1500, 50)
    Beep(1750, 50)
    Sleep(1000)
    SplashTextOn("WAIT ...", @CRLF & @CRLF & @CRLF & @CRLF & @CRLF & @CRLF & "Files are being copied ... " & _
                             @CRLF & @CRLF & @CRLF & "give the script time to do this ..." & @CRLF _
                ,"750","550","100","100","Comic Sans MS","16","16")     ;  width, height, x pos, y pos, "fontname", "fontsz", "fontwt"
    ;  Make sure a "SplashOff()" is below to turn off the splash screen.
    Sleep(500)
EndFunc
;--------------------------------------------------------------------------------------------------
Func _SplashTextOFF()
    Beep(1750, 50)
    Beep(1500, 50)
    Beep(1000, 50)
    Sleep(2000)
    ;---------------------------------------------------
    SplashOff()     ;  turns off Splash...On(...) above.
    ;---------------------------------------------------
EndFunc
;--------------------------------------------------------------------------------------------------

Thanks once again. I'm all set to listen and record my daily hour or so of news in the a.m. Handy for when I miss a particular detail since I'm rushing around. I can come back to the program later on to review news/commentaries.

Thanks. :)

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  
Followers 0