Jump to content

Need some help with arrays.


Recommended Posts

Okay here in a nutshell is what I am doing.

I am making a script to help automate covert and rename the NBC Nightly News that I pull from there site daily.

The main part of get getting the file can no long be automated as they have changed the format of there website.

But what I need help with is 2 things fist I have the script read and store the file name of the MP4 file in the folder.

Now I do that for to reasons the first part I have working right. It's so that it can brake the file name down in to an array.

That way I can use a renaming tool to rename the file so that my file can be run though a 2nd rename tool so that it gets formatted right so that Plex pulled the right info from thetvdb web site.

That is where I'm running into a wall.

Here is the thing I'm trying to do I have a CVS file that I Ioad into an array. It's formatted this way.

1,st

2,nd

3,rd

4,th

5,th

6,th

7,th

8,th

9,th

10,th

And so on down to 31,st

What I am trying to do is take that array part that is just the number of the date that comes from my file name and trying to match to the CSV file so that when it finds a match it added the th or rd nd part from the file to a new variable so that I can use that for the renaming part.

here is that code as I have worked it out so far.

$hSearch = FileFindFirstFile("Z:\Nighty FLV\*.flv")
Local $sFileName = "", $iResult = 0
$sFileName = FileFindNextFile($hSearch)
$bNewFile = $sFileName
FileClose($hSearch)
; And concatenate in the date/time macros
$aSplit = StringSplit($sFileName, " ")
$aSplit1 = StringSplit($aSplit[9], ")")
$aDateFile = $aSplit1[1] & ","
ConsoleWrite($aSplit)
$file = FileOpen("Z:\Nighty FLV\Data\date1.txt", 2)
FileWrite($file, $aDateFile)
FileClose($file)

#include <File.au3>
#include <Array.au3> ;THis line though line 37 is where I'm massing up something.
; Declare the 2 arrays
Global $aFile_1, $aFile_2
; Read the 2 files into the arrays
_FileReadToArray("Z:\Nighty FLV\Data\Date.txt", $aFile_1)
_FileReadToArray("Z:\Nighty FLV\Data\date1.txt", $aFile_2)
; For the lines you want
For $i = 2 To $aFile_1[0] - 2
; Does this line in the forst file exist in the second
    _ArraySearch($aFile_2, $aFile_1[$i])
    If @error Then
        ; If not then add to the second
        _ArrayAdd($aFile_2, $aFile_1[$i])
        $aFile_2[0] += 1
    EndIf
Next
; Write the new file = second file plus additional entries
_FileWriteFromArray("Z:\Nighty FLV\Data\Date_Combined.txt",$aFile_2, 0)
$file = FileOpen("Z:\Nighty FLV\Data\Date_Combined.txt", 0)
; Read in lines of text until the EOF is reached
$line = FileReadLine($file, 3)
$input = StringSplit($line, ",")
$sNewFile = $aSplit[1] & " " & $aSplit[2] & " " & $aSplit[3] & " " & $aSplit[4] & " " & $aSplit[5] & " " & $aSplit[6] & " " & $aSplit[7] & " " & $aSplit[8]& " " & $aSplit1[1] & ")"
$cNewFile = "NBC Nightly News" & " " & "-" & " " & "2015" & " " & "-" & " " & $aSplit[7] & " " & $aSplit[8] & " " &  $aSplit1[1] & $input[2] & ")"
FileClose($file)

Every time I run a look at the file it makes it looks something like this.

29
3,
2,nd
3,rd
4,th
5,th
6,th
7,th
8,th
9,th
10,th
11,th
12,th
13,th
14,th
15,th
16,th
17,th
18,th
19,th
20,th
21,st
22,nd
23,rd
24,th
25,th
26,th
27,th
28,th
29,th

Now as you can see I can't use this as the lines change all the time.

So I hope maybe someone could help me out here and tell me what I'm doing wrong?

And before you say it yes I have RTFM both online and offline, I have been a lurker of the forums for over 10 plus years. That is why I have never posted anything, because as I was once told shut your mouth and open your eyes and you just might find what your looking for.

The 2nd part is I would like to know how to wright out the variable that has the first file name into it into a temp file so that it can be load the next time the program ir run to check to see if that file that is in the folder is the same as what it worked on that last time and if so then exit the program.

Thanks for all of your time and help,

Michael

And PS the file is the full script I have come up with so far.

the Data.txt file is my CVS file and the Date1.txt file is what I output to use as input

and the last txt file is what it outputs. Just added those so you can see for your self's what's going on as typing is not a fave thing of mine to do as I can't spell to save my life.

test2.au3

Date.txt

Date_Combined.txt

date1.txt

Edited by michaelcrossland
misspellings added more files to be viewed for help.
Link to comment
Share on other sites

The main part of get getting the file can no long be automated as they have changed the format of there website.

Lol I like a challenge.

If I'm reading what you want to do correctly you could just add some if statements for when the number is 1-9.

If $Number == 1 Then
    Send("1st")
EndIF
If $Number == 2 Then
    Send("2nd")
EndIf

Your post is long and your code is complex. Are you trying to get rid of the ',' between the number and the rd,st and nd? Are you then trying to put the list in numerical order? Will there ever be more than 99 entries? 999 entries? indefinite?

Get Scite to add a popup when you use a 3rd party UDF -> http://www.autoitscript.com/autoit3/scite/docs/SciTE4AutoIt3/user-calltip-manager.html

Link to comment
Share on other sites

Lol I like a challenge.

If I'm reading what you want to do correctly you could just add some if statements for when the number is 1-9.

If $Number == 1 Then
    Send("1st")
EndIF
If $Number == 2 Then
    Send("2nd")
EndIf

Your post is long and your code is complex. Are you trying to get rid of the ',' between the number and the rd,st and nd? Are you then trying to put the list in numerical order? Will there ever be more than 99 entries? 999 entries? indefinite?

As for that part there is only 31 entries the same number of days in any given month, so if the Pope has not changed the way that works then there should only be 1-31.

Okay I'm am what I'm doing is telling autoit to set a variable with the file's name that is downloaded. Just to have you follow here lets say the file name is "Nightly News Full Broadcast (October 8) - NBC News.mp4" I do a split on that so that it splits at every space in the file name. Then I do a 2nd split to remove the ")" from the file name. Then I set a new variable with the 2nd split that has just the number ie 1-31. Then after that I have a txt file that is csv that has in the first column 1-31 then in the 2nd column I have the corresponding st nd rd th for each of the numbers. I need to match my number in the variable I set to one of the numbers in the txt file. That way I am able to set a new variable with the number & the corresponding st nd tr th so on and so on. The resion for doing that is so that I can use it as part of my re naming part of the script.

I use a 2nd program to rename the file after it has been converted and saved to the new folder where it will stay. The why I do that is because the file name has to come close to the name that TVDB has for that show other wise my 2nd rename program FileBot will not find a match and so then it will not rename the file the right way. That will cause Plex not to pickup the TVDB info for the file and show it in the shows lists.

And just as an FYI I am not doing this not myself. I'm doing it to get my Dad to move into the new way of doing things and get him out of 1990's and into the 2000's.

So any and all help with code and ways to get this working right will be so much looked forward to. As my Dad AKA 65 going on 5 is being a real pain in the back side about using the PMS that I have setup. Oh if this can be done with a IF loop so much the better but that is something, I would need to see in my code working for me to get my head around it. That is how I learn I have to be shown working code and then told why it's working after that I'll get it and will not forget it.

Your friend in hacking,

Michael

Link to comment
Share on other sites

Have you tried your code with the following line disabled?

;$aFile_2[0] += 1

I only had a quick look over your code, while passing by, but I imagine when you use _ArrayAdd, that $aFile_2[0] gets automatically updated and you shouldn't have to do it yourself, and in fact you are creating an error in doing so.

Make sure brain is in gear before opening mouth!
Remember, what is not said, can be just as important as what is said.

Spoiler

What is the Secret Key? Life is like a Donut

If I put effort into communication, I expect you to read properly & fully, or just not comment.
Ignoring those who try to divert conversation with irrelevancies.
If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it.
I'm only big and bad, to those who have an over-active imagination.

I may have the Artistic Liesense ;) to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)

userbar.png

Link to comment
Share on other sites

I use 3.3.14.1 and i can't confirm

Have you tried your code with the following line disabled?

;$aFile_2[0] += 1

I only had a quick look over your code, while passing by, but I imagine when you use _ArrayAdd, that $aFile_2[0] gets automatically updated and you shouldn't have to do it yourself, and in fact you are creating an error in doing so.

see this litle testscript:

#include <array.au3>

$sDelimtedString='1|2|3|4'

$aTest=StringSplit($sDelimtedString,'|')
MsgBox(0,'Elements in array',$aTest[0]&@CRLF)

_ArrayAdd($aTest,5)

_ArrayDisplay($aTest)
MsgBox(0,'Elements in array',$aTest[0]&@CRLF)

There are 5 elements in the array after _ArrayAdd but elelement 0 has the value 4

Link to comment
Share on other sites

If it's just to rename the file to change the date, would this work for you?

$TVShow = "Nightly News Full Broadcast (October 13) - NBC News.mp4"

    Select
        Case StringInStr($TVShow, "11)") > 0
            $TVShow = StringReplace($TVShow, ")", "th")
        Case StringInStr($TVShow, "1)") > 0
            $TVShow = StringReplace($TVShow, ")", "st")
        Case StringInStr($TVShow, "12)") > 0
            $TVShow = StringReplace($TVShow, ")", "th")
        Case StringInStr($TVShow, "2)") > 0
            $TVShow = StringReplace($TVShow, ")", "nd")
        Case StringInStr($TVShow, "13)") > 0
            $TVShow = StringReplace($TVShow, ")", "th")
        Case StringInStr($TVShow, "3)") > 0
            $TVShow = StringReplace($TVShow, ")", "rd")
        Case Else
            $TVShow = StringReplace($TVShow, ")", "th")
    EndSelect

    $TVShow = StringReplace($TVShow, "(", "")
    MsgBox(0,"",$TVShow)

 

 

Edited by MuffinMan
Forgot to account for the 12th/13th
Link to comment
Share on other sites

my suggestion is do a switch statement for the date

$day = 4
local $sday
Switch $day
    Case  1
        $sday = "1st"
    Case  2
        $sday = "2nd"
    Case  3
        $sday = "3rd"
    Case  4
        $sday = "4th"
    Case  5
        $sday = "5th"
    Case  6
        $sday = "6th"
    Case  7
        $sday = "7th"
    Case  8
        $sday = "8th"
    Case  9
        $sday = "9th"
    Case  10
        $sday = "10th"
    Case  11
        $sday = "11th"
    Case  12
        $sday = "12th"
    Case  13
        $sday = "13th"
    Case  14
        $sday = "14th"
    Case  15
        $sday = "15th"
    Case  16
        $sday = "16th"
    Case  17
        $sday = "17th"
    Case  18
        $sday = "18th"
    Case  19
        $sday = "19th"
    Case  20
        $sday = "20th"
    Case  21
        $sday = "21st"
    Case  22
        $sday = "22nd"
    Case  23
        $sday = "23rd"
    Case  24
        $sday = "24th"
    Case  25
        $sday = "25th"
    Case  26
        $sday = "26th"
    Case  27
        $sday = "27th"
    Case  28
        $sday = "28th"
    Case  29
        $sday = "29th"
    Case  30
        $sday = "30th"
    Case  31
        $sday = "31st"
EndSwitch
ConsoleWrite($sday & @CRLF

The 2nd part is I would like to know how to wright out the variable that has the first file name into it into a temp file so that it can be load the next time the program ir run to check to see if that file that is in the folder is the same as what it worked on that last time and if so then exit the program.

$read = FileRead('z:\index.txt');read the file that holds the list of programs processed
if StringInStr($read,'newfilename') then Exit ;exit if the original filename is there
;write the original filename
$fo = FileOpen('z:\index.txt',1)
FileWrite($fo,'newfilenam' & @crlf)
FileClose($fo)
;process it

 

Link to comment
Share on other sites

There are 5 elements in the array after _ArrayAdd but elelement 0 has the value 4

My apologies, you are correct, and I am dumbfounded that it is the case.

Seems like oxymoron behavior to me, but no doubt related to the fact that $array[0] doesn't always indicate the count. It may also be the case, that with later versions of AutoIt, where you can also add a delimited string, that may have a bearing.

Still, there should be a parameter to make it update the count, at the very least .... very odd to be like it is, only doing half the job. Also a bit remiss that nothing is said about this issue in the Help file. For me, it breaks the common sense behavior, that AutoIt is usually so good at. Still, it is in a UDF, which probably explains the lapse.

This situation probably explains why I cannot recall ever using the command, as i would have discovered that behavior immediately and so opted for another method. I do have a vague recollection of such.

So $aFile_2[0] += 1 is obviously fine.

P.S. I have just now recalled, that a few months ago, I tried to use _ArrayConcencate for the first time and ended up giving up on it, as it didn't work straight out of the box, and I was in a hurry. No doubt i saw $array[0] wasn't being updated and looked no further than that, presuming a bug or something. That just goes to illustrate that it is wrong as it is, as it is not doing the logically assumed thing. _ArrayInsert is the same and probably some others too.

Edited by TheSaint

Make sure brain is in gear before opening mouth!
Remember, what is not said, can be just as important as what is said.

Spoiler

What is the Secret Key? Life is like a Donut

If I put effort into communication, I expect you to read properly & fully, or just not comment.
Ignoring those who try to divert conversation with irrelevancies.
If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it.
I'm only big and bad, to those who have an over-active imagination.

I may have the Artistic Liesense ;) to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)

userbar.png

Link to comment
Share on other sites

I wouldn't want either of those functions to update the 0 element of the array, I tend to use 0 based arrays, and not 1 based with a count in 0, when I write code. I would leave it with the person writing the script to decide whether to update an element or not.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

  • Moderators

TheSaint,

As the author of the latest versions of the _Array* functions which according to you should automatically update the [0] element I am afraid that I cannot disagree more with that idea. As has been pointed out by BrewmanNH, not everyone uses the [0] element as a count so any "auto-increase" would have to be controlled by yet another parameter - and there are quite enough in most of these functions already. And the equivalent functions in the previous version of the library did not amend the [0] element either, so your surprise at this behaviour is a little late to the party.

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

You could just do it this way to increment your count along with the _arrayadd.

#include <array.au3>

$sDelimtedString='1|2|3|4'

$aTest=StringSplit($sDelimtedString,'|')
MsgBox(0,'Elements in array',$aTest[0]&@CRLF)

$aTest[0] = _ArrayAdd($aTest,5)

_ArrayDisplay($aTest)
MsgBox(0,'Elements in array',$aTest[0]&@CRLF)

 

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Link to comment
Share on other sites

@boththose - I tried that as soon as i realized the situation, and it didn't work with v3.3.0.0. It may work with later versions of AutoIt. EDIT - I was using the '5' as a string variable though ($val = "5"), so that may make a difference. Will have to test your version when I get the chance. EDIT - Nope, made no difference. Does that work for you, or were you guessing like I was earlier? ;)

@Melba23 etc - I am no doubt late to the party, and I did say I expected it was due to the [0] being a variable use thing. I still stand by what I said though, as regards to no mention in the Help file, where a solution should also be given, in my view.

And nothing changes the fact, that i expected, as would many others, and quite a reasonable expectation, that Array[0] would be updated. One cannot also get away from the point of the updating (adding) being only half done.

Is adding another parameter (one that should have been there all along in my opinion). really such an imposition?
I agree with what BrewManNH wrote, that it should be user choice, but user choice in the _ArrayAdd command, as a parameter.

Personally, I only ever use $array[0] as the count, but I respect that others don't.
So my approach has always been that simplest is best, and AutoIt on the whole, has generally lived up to that.

P.S. I guess I'm late to the party, because I just never really needed to use most of the UDF array functions until more recently. I can certainly see how their behavior would deter newbies, through lack of understanding, through lack of no explanation ... probably why many see arrays as difficult, as evident by regular comments in the Help forums.

Edited by TheSaint

Make sure brain is in gear before opening mouth!
Remember, what is not said, can be just as important as what is said.

Spoiler

What is the Secret Key? Life is like a Donut

If I put effort into communication, I expect you to read properly & fully, or just not comment.
Ignoring those who try to divert conversation with irrelevancies.
If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it.
I'm only big and bad, to those who have an over-active imagination.

I may have the Artistic Liesense ;) to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)

userbar.png

Link to comment
Share on other sites

@TheSaint -  it works fine.  Why wouldnt it?  It is just setting the return value from arrayadd as the new element 0.  Unless there is something desired I am missing.

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...