PatrickUK Posted January 30, 2011 Share Posted January 30, 2011 Hi all, I am trying to write a script which takes user input in the form of the day of the week (Mon Tue etc) and based on that input then goes on to rename a file. This is the first time that I have used a pop up window that needs user input. This is what I have so far .. #include <GUIConstantsEx.au3> $input1 = inputbox ("billcentre backup util", "Enter the current day. Mon Tue etc") GUICtrlRead($input1) runwait ("cmd /c " & "echo " & $input1 & " > day.txt", "", @SW_HIDE) $File = FileOpen("day.txt", 0) $Read = FileReadLine($File, 1) $array = StringRegExp($Read, 0); this is where I get lost. I am reading up on what an 'array' is, so not sure if I should be using it anyway! FileClose($file) What I would like to make this do is, for example, if the user inputs 'Mon' to rename Mon.xml to current.xml. If its 'Tue', then Tue.xml is renamed to current.xml etc, etc. I have a feeling that I am going to need to understand 'loops' and 'if, then' but not really sure yet. If anyone could give me some pointers I would be most greatful. Thx in advance - Patrick. Link to comment Share on other sites More sharing options...
jvanegmond Posted February 2, 2011 Share Posted February 2, 2011 This is not really a programming challenge, but more of a user challenge. First of all, you are making the user enter the current day in the format of: Mon, tue, wed. This is error-prone and someone is going to mess it up. It's fairly easy to get this information from the Windows clock, so I have decided to show you that method instead.For the rest, I think you were going for a line-by-line copy of the file. That's not necessary since you can just move the file in one go with FileMove: Which for a computer is the same as renaming a file.Here is the code. I hope you can make good use of it.$fileSource = "" Switch @WDAY ; Numeric day of week. Range is 1 to 7 which corresponds to Sunday through Saturday. Case 1 ; Case the current day is Sunday $fileSource = "Sun.xml" Case 2 ; Case current day Monday $fileSource = "Mon.xml" Case 3 ; Case Tuesday .. etc etc .. etc.. etc .. $fileSource = "Tue.xml" Case 4 Case 5 Case 6 Case 7 EndSwitch FileMove($fileSource, "current.xml") ; FileRename does not exist, use FileMove insteadCase 4,5,6,7 are left open cause I needed my time to type this post and teach you how to do it instead. github.com/jvanegmond Link to comment Share on other sites More sharing options...
PatrickUK Posted February 3, 2011 Author Share Posted February 3, 2011 Very many thanks Manadar, I have just arrived back at work today and will take a look at this over the weekend when it will be quieter. This is a far more elegant way of handling the problem. I look forward to getting my teeth into it over the weekend and will post an update. Regards - Patrick. Link to comment Share on other sites More sharing options...
PatrickUK Posted February 5, 2011 Author Share Posted February 5, 2011 This works perfectly! Thankyou so much Manadar, all I needed to do was to continue with your examples and it worked first time. I do have a question resulting in what I have learned from this use of @WDAY and the use of $filesource ... is it possible to make windows 'overwrite' an old file. I noticed that I could not do this with my 'current.xml' file (I have to rename it back, or delete the file before using the script again). On another note, the link from @WDAY to the macro page has given me an idea as I've spotted an @HOUR macro which I could use to tidy up the first script which I tried! Thanks again Manadar - Regards, Patrick. Link to comment Share on other sites More sharing options...
jvanegmond Posted February 5, 2011 Share Posted February 5, 2011 FileMove has a 3rd parameter which is the optional flag. It is described as (from the help file): [optional] this flag determines whether to overwrite files if they already exist: Can be a combination of the following: 0 = (default) do not overwrite existing files 1 = overwrite existing files 8 = Create destination directory structure if it doesn't exist (See Remarks).If you changed the line: FileMove($fileSource, "current.xml") To: FileMove($fileSource, "current.xml", 1) Then it will overwrite the existing file. github.com/jvanegmond Link to comment Share on other sites More sharing options...
PatrickUK Posted February 6, 2011 Author Share Posted February 6, 2011 Thankyou for the ' ,1 ' tip Manadar, I had seen that in the manual and quite forgotten about it. I have got round that problem by adding this to the script ... SNIP--> Case 6 ; Case current day Friday $fileSource = "C:\G6Autorun\billcentre\billcentre.thu.xml" Case 7 ; Case current day Saturday $fileSource = "C:\G6Autorun\billcentre\billcentre.fri.xml" EndSwitch FileMove($fileSource, "billcentre.xml") ; FileRename does not exist, use FileMove instead Sleep (28000000) If @WDAY = 1 Then FileMove("C:\G6Autorun\billcentre\billcentre.xml", "C:\G6Autorun\billcentre\billcentre.sat.xml") Endif If @WDAY = 2 Then FileMove("C:\G6Autorun\billcentre\billcentre.xml", "C:\G6Autorun\billcentre\billcentre.sun.xml") Endif etc, etc In this way the files are renamed back to their original names at the end of the working day - so can be reused again another day. The data displays in a chart on a large plasma screen on the wall and is only used when the live feed goes down so the data contained in the xml files is sample data but better than showing an empty graph! Link to comment Share on other sites More sharing options...
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