AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

break script at end of text file - no loop

 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
Zvi



Joined: 22 Aug 2008
Posts: 25

PostPosted: Fri Aug 22, 2008 12:08 pm    Post subject: break script at end of text file - no loop Reply with quote

I have text files that look like this: (They are chapter ponts exported from a video editing program)

1,"00:00:00:00","Clip"
2,"00:04:20:17","Mifgash"
3,"00:05:50:14","Siyur"
4,"00:08:23:02","Promo"
5,"00:11:49:11","Hall"
6,"00:14:55:23","Ketuba"
7,"00:16:18:22","Hupa"
8,"00:19:18:19","NULL"
9,"00:22:28:03","Kenissa - Dance 1"
10,"00:27:36:00","NULL"

Sometimes these files can have 3 lines and sometimes over 40.

I recorded a "copy\paste" of each time code and pasted them into Adobe Encore DVD and created a chapter in Encore DVD.

When running the script, it works like a charm. (Adobe Encore doesn't allow importing chapters from other programs so this is a big time saver for me)

My question is, how do I get the AutoKey script to detect the last line in the text file and stop the script? (I would then record a 50 line text file (the most I ever need) and the script would go through the lines until the last line and stop.

Or better yet, is there a way to have the script just detect the charachters inside the quotations (e.g. 00:05:50:14 ) (I don't need to copy\paste any of the rest) so I only have to record ONE line and have the script loop until it detects there are no more lines?

Thanks
Back to top
View user's profile Send private message
HugoV



Joined: 27 May 2007
Posts: 650

PostPosted: Fri Aug 22, 2008 12:17 pm    Post subject: Reply with quote

1) Look into Loop, parse file, it will automatically stop at the last line.
2) You could lookinto RegExMatch, but if you find that difficult you could
StringGetPos to get the position of the first " and then use StringMid
to "cut" the string you need.

Try the loop and String method, post the code you have if you
can't get it to work.
_________________
When parsing a CSV file use Loop, parse, Inputvar, CSV!
Back to top
View user's profile Send private message
SKAN



Joined: 26 Dec 2005
Posts: 6264

PostPosted: Fri Aug 22, 2008 12:56 pm    Post subject: Reply with quote

if you are using FileReadLine, you can check the Errorlevel and Break.

Smile
_________________
Back to top
View user's profile Send private message
Zvi



Joined: 22 Aug 2008
Posts: 25

PostPosted: Fri Aug 22, 2008 1:55 pm    Post subject: con Reply with quote

It says that the characters \.*?+[{|()^$ must be preceded by a backslash.

Since my file is like this:

1,"00:00:00:00","Dance 1"
2,"00:12:54:21","Hina"
3,"00:34:30:21","Dance 2"
4,"01:21:05:02","NULL"

All I need is the 00:12:54:21 from each line.

I tried
Loop, FileRead ,chapters, %A_Temp%\002.csv
{
Loop, parse, A_LoopReadLine, %A_Tab%
{
FoundPos := RegExMatch(chapters, ".+", chapters)
MsgBox, %chapters%
}
}

and
FoundPos := RegExMatch(chapters, \".+\", chapters)

but I can't figure it out. I think I'm getting it all wrong.

How can I loop through the above text and get only the timecode copied to the clipboard?

thanks
Back to top
View user's profile Send private message
Sivvy



Joined: 21 Jul 2008
Posts: 711
Location: Calgary, AB, Canada

PostPosted: Fri Aug 22, 2008 2:09 pm    Post subject: Reply with quote

Code:
Loop, Read, PathAndNameOfFileToReadFrom
{
    StringSplit, FullString, A_LoopField, "
    FileAppend, %FullString2%, PathAndNameOfFileToWriteTo
}


Does this work? Just change the File names to what they are supposed to be.
Back to top
View user's profile Send private message MSN Messenger
Zvi



Joined: 22 Aug 2008
Posts: 25

PostPosted: Fri Aug 22, 2008 2:14 pm    Post subject: to Sivvy Reply with quote

Thanks for the reply.

All it does is create a new file for PathAndNameOfFileToWriteTo but it's an empty file.

Also, I don't want to create a new file, I just want to copy the timecodes (e.g. 00:01:22:03) to the clipboard.
Back to top
View user's profile Send private message
Sivvy



Joined: 21 Jul 2008
Posts: 711
Location: Calgary, AB, Canada

PostPosted: Fri Aug 22, 2008 2:21 pm    Post subject: Reply with quote

Did you change the names like I said at the bottom of my post? It's not going to read from a file that doesn't exist.
Back to top
View user's profile Send private message MSN Messenger
Zvi



Joined: 22 Aug 2008
Posts: 25

PostPosted: Fri Aug 22, 2008 2:29 pm    Post subject: con Reply with quote

Yes I did. I'll try it again.

To those who worte about StringGetPos, this would work:

Loop, read, C:\002.csv
{
Loop, parse, A_LoopReadLine, %A_Tab%
{
StringGetPos, pos, A_LoopField, " ; [, , 3] for second one
if pos >= 0
MsgBox, The string was found at position %pos%.
}
}

but I don't need this because my two (") characters are ALWAYS at position 2 and 14. Now I just need to know how to get the timecode inbetween them into the clipboard so I can have the script paste them somewhere else.
Back to top
View user's profile Send private message
Zvi



Joined: 22 Aug 2008
Posts: 25

PostPosted: Fri Aug 22, 2008 2:32 pm    Post subject: con Reply with quote

I tried


Loop, Read, C:\002.csv
{
StringSplit, FullString, A_LoopField, "
FileAppend, %FullString2%, C:\008.csv
}

But 008.csv just is empty.
Back to top
View user's profile Send private message
Slanter



Joined: 28 May 2008
Posts: 397
Location: Minnesota, USA

PostPosted: Fri Aug 22, 2008 2:58 pm    Post subject: Reply with quote

Code:
Loop, Read, C:\002.csv
{
   Time := RegExReplace(A_LoopReadLine,"^\d+,.((\d{2}:?){4}).,.+$","$1")
   MsgBox % Time
}
Or
Code:
Loop, Read, C:\002.csv
{
   Loop, Parse, A_LoopReadLine, CSV
   {
      If (A_Index = 2) {
         Time := A_LoopField
         Break
      }
   }
   MsgBox % Time
}


Question
_________________
Unless otherwise stated, all code is untested

(\__/) This is Bunny.
(='.'=) Cut, copy, and paste bunny onto your sig.
(")_(") Help Bunny gain World Domination.
Back to top
View user's profile Send private message Visit poster's website
Zvi



Joined: 22 Aug 2008
Posts: 25

PostPosted: Sat Aug 23, 2008 8:05 am    Post subject: YES Reply with quote

These both worked great!!

Thanks so much!
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group