Page 1 of 1

Current Date as a Directory name

Posted: 12 Jul 2017, 11:44
by Skyyh
Hi,

I’d like to create directory in my root C: and name it “! 07-12-17” which I can do. But I want Change the date every day to the new date of the day, then compile the script and put in my RUN command in the registry. That way when boot up first thing in the morning or otherwise the current date is in my root C: directory. And I want to replace the Directory not a many Directories with older dates. Needles to say I’m not that far along with AutoHotKey.

I very much appreciate you help. :?:

Re: Current Date as a Directory name

Posted: 13 Jul 2017, 13:31
by Sam_
Use at your own risk!

Code: Select all

#Persistent

SetTimer, UpdateFolder, 300000 ; Check ~ every 5 min
Return


UpdateFolder(){
	FormatTime, Today, , ! MM-dd-yy ; Format today's date in the format you specified
	Loop, C:\*, 2, 0 ; Loop through the folders on the top level of the C drive
		{
		SplitPath, A_LoopFileLongPath, OutFileName, OutDir ; Split the current folder's long path into sections
		If RegExMatch(OutFileName,"^! [0-9]{2}-[0-9]{2}-[0-9]{2}$") ; Check to see if the folder we are on is the one formatted the way we want
			{
			FileMoveDir, %A_LoopFileLongPath%, %OutDir%\%Today%, R ; If it is, rename it using today's date, formatted above
			Break ; If the proper folder has been found, stop searching additional folders on the C drive
			}
		}
}

Re: Current Date as a Directory name

Posted: 13 Jul 2017, 18:10
by SkyByDay
Sam_
Thank you. I'll try the script.

Re: Current Date as a Directory name

Posted: 15 Jul 2017, 09:24
by SkyByDay
Sam_
It worked in 3 of my PC's. THANK you. I was trying to do this four years!

But on my MAC Book Pro 4.1 with Windows 7-64 Ultimate installed I get the following error and the script won't compile:
Error: Target label does not exist

Line#

012: SetTimer, UpdateFolder, 300000

I scratch my bard old dude wooden head and can't figure out why. But if I can't get an answer on the forum that is perfectly ok. I use that laptop very little. It really doesn't matter if the date does update with AHK. I so thankful that I can run it on my PC's.

Re: Current Date as a Directory name

Posted: 15 Jul 2017, 10:54
by Sam_
Sounds like you are using an older version of AHK. You need at least v1.1.20 for SetTimer to use a function instead of a label (which is what I have done).

Re: Current Date as a Directory name

Posted: 15 Jul 2017, 13:47
by SkyByDay
Sam_
You were right I had a 2009 version AHK installed. The script works fine now.
Thanks again!!!!