MiriamSapir Posted May 9, 2011 Posted May 9, 2011 Hi,I'm completely new to AutoIt and don't have much knowledge and experience in programming. I apologize in advance if I ask questions that seem obvious or silly. I have a routine which I follow every sunday. It includes many many actions.To start with, I need to create a folder with today's date. Easy enough:DirCreate("C:\Sunday Reports\" & @MON & "-" & @MDAY & "-" & @YEAR )However, I need the month to be spelled out, e.g. April-3-2011I tried this, but AutoIt just created a folder with the day and year:Local $aMonths[13] = [12, "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"]DirCreate("C:\Sunday Reports\" & $aMonths & "-" & @MDAY & "-" & @YEAR )Then I need to create subfolders, which again, I'm missing something in the syntax:DirCreate("C:\Sunday Reports\" & @MON & "-" & @MDAY & "-" & @YEAR )DirCreate("C:\Sunday Reports\" & @MON & "-" & @MDAY & "-" & @YEAR\ & "CCC" )Tried searching the forum and the help topics, which helped me partially, but got stuck with the months. Thanks, Miriam
wakillon Posted May 9, 2011 Posted May 9, 2011 (edited) Welcome to the forum ! Try this :Local $aMonths[13] = [12, "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"] For $_I = 1 To 12 DirCreate ( "C:\Sunday Reports\" & $aMonths[$_I] & "-" & @MDAY & "-" & @YEAR & '\ccc' ) Next Edited May 9, 2011 by wakillon AutoIt 3.3.14.2 X86 - SciTE 3.6.0 - WIN 8.1 X64 - Other Example Scripts
MiriamSapir Posted May 9, 2011 Author Posted May 9, 2011 Thanks a lot! That worked. Can I ask you about the logic of the syntax? I'm trying to learn how to write scripts myself For ... Next: what prevents AutoIt from creating 12 folders? How did it know to create today's month? I hope it's OK I'm asking. Thanks, Miriam
MiriamSapir Posted May 9, 2011 Author Posted May 9, 2011 Sorry - I just looked again and realized that the potential problem I described below indeed occurred! AutoIt created 12 folders with today's date but 12 different months! All I needed is to create ONE folder with today's month. Instead it created this: May-09-2011 June-09-2011 July-09-2011 etc. Thanks again, Miriam
saywell Posted May 9, 2011 Posted May 9, 2011 This is a quick and dirty solution - put it in a function and call it before you create the directory, and use $mon instead of @mon in the name. Select Case @MON = 1 $Mon = "January" Case @MON = 2 $Mon = "February" Case @MON = 3 $Mon = "March" Case @MON = 4 $Mon = "April" Case @MON = 5 $Mon = "May" Case @MON = 6 $Mon = "June" Case @MON = 7 $Mon = "July" Case @MON = 8 $Mon = "August" Case @MON = 9 $Mon = "September" Case @MON = 10 $Mon = "October" Case @MON = 11 $Mon = "November" Case @MON = 12 $Mon = "December" EndSelect William
wakillon Posted May 9, 2011 Posted May 9, 2011 (edited) One folder...ok#include <Date.au3> DirCreate ( "C:\Sunday Reports\" & _DateToMonth ( @MON, 1 ) & "-" & @MDAY & "-" & @YEAR & '\ccc' )hope it's the good one ! Edit : see helpfile for _DateToMonth if you want short or complete name. Edited May 9, 2011 by wakillon AutoIt 3.3.14.2 X86 - SciTE 3.6.0 - WIN 8.1 X64 - Other Example Scripts
MiriamSapir Posted May 9, 2011 Author Posted May 9, 2011 This is a quick and dirty solution - put it in a function and call it before you create the directory, and use $mon instead of @mon in the name. Select Case @MON = 1 $Mon = "January" Case @MON = 2 $Mon = "February" Case @MON = 3 $Mon = "March" Case @MON = 4 $Mon = "April" Case @MON = 5 $Mon = "May" Case @MON = 6 $Mon = "June" Case @MON = 7 $Mon = "July" Case @MON = 8 $Mon = "August" Case @MON = 9 $Mon = "September" Case @MON = 10 $Mon = "October" Case @MON = 11 $Mon = "November" Case @MON = 12 $Mon = "December" EndSelect William Sorry, I'm a real beginner, and am a little bit embarrassed to ask this , but what do you mean by "put it in a function and call it before. Thanks again. Miriam
saywell Posted May 9, 2011 Posted May 9, 2011 (edited) expandcollapse popupGlobal $Mon ; declares global variable - another quick and dirty method, ; rather than passing the variable in the return value. Monthname() ; runs the function which sets the value of $Mon DirCreate("C:\Sunday Reports\" & $Mon & "-" & @MDAY & "-" & @YEAR ) ; your bit, with $Mon substituted for @MON Func Monthname() Select Case @MON = 1 $Mon = "January" Case @MON = 2 $Mon = "February" Case @MON = 3 $Mon = "March" Case @MON = 4 $Mon = "April" Case @MON = 5 $Mon = "May" Case @MON = 6 $Mon = "June" Case @MON = 7 $Mon = "July" Case @MON = 8 $Mon = "August" Case @MON = 9 $Mon = "September" Case @MON = 10 $Mon = "October" Case @MON = 11 $Mon = "November" Case @MON = 12 $Mon = "December" EndSelect endfunc ; ===> Monthname William Edited May 9, 2011 by saywell
Moderators Melba23 Posted May 9, 2011 Moderators Posted May 9, 2011 MiriamSapir, Sorry, I'm a real beginner, and am a little bit embarrassed to ask thisDo not be embarrassed - we all started at that point! Reading the Help file (at least the first few sections - Using AutoIt, Tutorials and the first couple of References) will help you enormously. You might also look at the excellent tutorials that you will find here and here - you will find other tutorials in the Wiki (the link is at the top of the page). There are even video tutorials on YouTube if you prefer watching to reading. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
MiriamSapir Posted May 9, 2011 Author Posted May 9, 2011 MiriamSapir, Do not be embarrassed - we all started at that point! Reading the Help file (at least the first few sections - Using AutoIt, Tutorials and the first couple of References) will help you enormously. You might also look at the excellent tutorials that you will find here and here - you will find other tutorials in the Wiki (the link is at the top of the page). There are even video tutorials on YouTube if you prefer watching to reading. M23 Thank you all for your explanations and suggestions! This is really very helpful and much appreciated. While I did read the manuals and searched the UDF, they helped me get started but I still get stuck often. Thank you everyone! Miriam
MiriamSapir Posted May 9, 2011 Author Posted May 9, 2011 One folder...ok #include <Date.au3> DirCreate ( "C:\Sunday Reports\" & _DateToMonth ( @MON, 1 ) & "-" & @MDAY & "-" & @YEAR & '\ccc' ) hope it's the good one ! Edit : see helpfile for _DateToMonth if you want short or complete name. This did the job. And after reading the helpfile, I understand the sytanx much better. The trouble I have with the manuals, or the functions actually, is sometimes I look for a phrase and it's defined differently in the guide. For example: I'm looking to sort files in windows explorer but could not find something tailored to my needs. Then, after searching the forum, someone mentioned list_view, or something like that, which also does sorting. But I would have never found it unless I looked at each function. Thanks! By the way,
wakillon Posted May 9, 2011 Posted May 9, 2011 AutoIt is the best scripting language !Glad to help you, and good continuation ! AutoIt 3.3.14.2 X86 - SciTE 3.6.0 - WIN 8.1 X64 - Other Example Scripts
Malkey Posted May 9, 2011 Posted May 9, 2011 .... However, I need the month to be spelled out, e.g. April-3-2011 I tried this, but AutoIt just created a folder with the day and year: Local $aMonths[13] = [12, "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"] DirCreate("C:\Sunday Reports\" & $aMonths & "-" & @MDAY & "-" & @YEAR ) Then I need to create subfolders, which again, I'm missing something in the syntax: DirCreate("C:\Sunday Reports\" & @MON & "-" & @MDAY & "-" & @YEAR ) DirCreate("C:\Sunday Reports\" & @MON & "-" & @MDAY & "-" & @YEAR\ & "CCC" ) ....Try this. Local $aMonths[13] = [12, "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"] ConsoleWrite("C:\Sunday Reports\" & $aMonths[@MON] & "-" & @MDAY & "-" & @YEAR & @CRLF) ConsoleWrite("C:\Sunday Reports\" & $aMonths[@MON] & "-" & @MDAY & "-" & @YEAR & "\CCC" & @CRLF) ;DirCreate("C:\Sunday Reports\" & $aMonths[@MON] & "-" & @MDAY & "-" & @YEAR) ;DirCreate("C:\Sunday Reports\" & $aMonths[@MON] & "-" & @MDAY & "-" & @YEAR & "\CCC") @saywell Because all the expressions of case statements in this Select...Case...EndSelect routine start with @MON = .... , I believe using "Switch @MON" in a Switch...Case...EndSwitch routine would be easier. But in this example, selecting the appropiate element directly from an array of months would be more efficient. ... Edit : see helpfile for _DateToMonth if you want short or complete name. @wakillon Just a heads up to the bug with getting the short month name from _DateToMonth. Note in the _DateToMonth() function in the Date.au3 include file, the $aMonthNumberAbbrev array does not have the conventional three character short names of every month.
wakillon Posted May 10, 2011 Posted May 10, 2011 @wakillonJust a heads up to the bug with getting the short month name from _DateToMonth. Note in the _DateToMonth() function in the Date.au3 include file, the $aMonthNumberAbbrev array does not have the conventional three character short names of every month.Yes, June, July and Sept have 4 characters short names format, instead of others. AutoIt 3.3.14.2 X86 - SciTE 3.6.0 - WIN 8.1 X64 - Other Example Scripts
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now