AutoHotkey Community

It is currently May 27th, 2012, 8:16 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 5 posts ] 
Author Message
PostPosted: January 19th, 2012, 8:13 am 
Offline

Joined: January 17th, 2012, 7:28 pm
Posts: 2
Hello ahk world:

I'm totally newbie in ahk scripting, and I would like to do a very simple thing.

I have a Unicode text file containing file names. It's very simply structured: old file name, space, new file name)

E:\0AAA\00001Test.pdf E:\0AAA\00001Test-世界科技(1).pdf
E:\0AAA\00002Test.pdf E:\0AAA\00002Test-世界科技(2).pdf

I would like to retrieve the different filenames into variables FA and FB

Code:
Loop, read,  E:\0AAA\BiBlistULight.txt
{
    LineNumber = %A_Index%
    Loop, parse, A_LoopReadLine, %A_Space%
    {
        If (A_Index = 1)
   FA := %A_LoopField%
        Else if (A_Index = 2)
   FB := %A_LoopField%

        MsgBox, %FA% will be renamed %FB%
            return
 }
}


At execution, I have the message "The following variable name contains an illegal character : "E:\0AAA\00001Test.pdf" at
FA := %A_LoopField%

It may seem obvious to experimented scripters, but I would like to know if there is a way to put full file names into variables?

Thanks in advance.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 19th, 2012, 8:34 am 
Offline
User avatar

Joined: September 1st, 2011, 8:21 pm
Posts: 368
Location: California
Code:
Loop, read,  E:\0AAA\BiBlistULight.txt
{
    LineNumber = %A_Index%
    Loop, parse, A_LoopReadLine, %A_Space%
    {
        If (A_Index = 1)
            FA = %A_LoopField%      ; either use = and %%
        Else if (A_Index = 2)
            FB := A_LoopField       ; or use := and no %%
    }
    MsgBox, %FA% will be renamed %FB%   ; move outside the inner loop
}
return   ; move to end


Report this post
Top
 Profile  
Reply with quote  
 Post subject: spaced out
PostPosted: January 19th, 2012, 8:39 am 
Offline

Joined: January 21st, 2009, 5:49 pm
Posts: 176
Since a space is a legal filename character it's not the best to use as a separator. May be better to use like a vertical bar, semicolon or even have the old names on the odd lines and the new names on the even lines. This works pretty well. I've used that for loading maps, or associative arrays, from ftext files. It's a pretty simple and robust way to do it.

_________________
"I don't want to belong to any club that would have me as a member."
- Groucho Marx


Last edited by MilesAhead on January 19th, 2012, 8:40 am, edited 1 time in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 19th, 2012, 8:39 am 
Offline
User avatar

Joined: November 19th, 2010, 3:12 pm
Posts: 787
Location: At my computer
Darn it! You beat me to it Alpha Bravo. :)

_________________
"My dear Mr Gyrth, I am never more serious than when I am joking."
~Albert Campion

My personal site


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 19th, 2012, 8:47 am 
Offline

Joined: January 17th, 2012, 7:28 pm
Posts: 2
thanks a lot for your quick replies, guys!

Code:
Loop, read,  E:\0AAA\BiBlistULight.txt
{
    LineNumber = %A_Index%
    Loop, parse, A_LoopReadLine, %A_Space%
    {
                If (A_Index = 1)
   FA := A_LoopField
        Else if (A_Index = 2)
   FB := A_LoopField
             
    }
MsgBox, %FA% will be renamed %FB%
}
 return


The first script is always the hardest ... :D :D :D


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: BrandonHotkey, immunity, migz99, sjc1000, Yahoo [Bot] and 63 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
cron
Powered by phpBB® Forum Software © phpBB Group