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 

AutoNaming a file/variable

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






PostPosted: Tue Mar 08, 2005 7:56 am    Post subject: AutoNaming a file/variable Reply with quote

hi...
i am trying to make a script whose objective is this:

to allow user to first enter a PATH e.g(C:\, C:\Program Files\ ...etc) to index all the files along their FULL PATH and FULL NAME to a file
the first part goes something like this:

Code:
Loop, %ProgramFiles%\*.htm, , 1  ; Recurse into subfolders.
{
    FileAppend,1+1%A_LoopFileFullPath%. (%A_LoopFileName%)`n, Test2.txt


}


and then to allow user to enter the NAME of the file (e.g name.ahk) to RUN THAT FILE..... now as i see it .... the only way to do this... is to first Split the contents of every line into the PATH and NAME... that goes somewhat like this:

Code:
Loop, Read, test.txt, OutputFile.txt
{
    StringReplace, Line, A_LoopReadLine, (, `, ; replace left brackets
    StringReplace, Line, Line, ), `, ; replace right brackets
    StringSplit, Field, Line, `, ; split string into fields
    FileAppend, %Field2%`n ; write field2 to outputfile
}
(THANKS BoBo)

now i'll have to store EACH LINE of the new file to a VARIABLE... so i can then add something like ... compare the INPUT from the user to ALL THE VARIABLES... OR... compare the INPUT of the user to ALL THE TEXT in the file... and STORE the LINE NUMBER of the matched string so it can be used to reference later...

then to make a stationary file (THORUGH THE SCRIPT).. that will contain :

Code:
Run, %full path of the file matched%



now... the problem for me (AT THIS TIME) is how can i make the SCRIPT READ EACH LINE OF THE TEXT AND SAVE IT AS (vname1, vname2, vname3.....) so PLEEEEEEEEEEEEEAAAAAAAASSSSSSSSSEEEEEEEEE help me on this one ... and also if u have any tips for the remaining script ... cause i got my papers after two months...and i dont have much time to spent on this... but still i need to finish it today ...(its not syllabus of course Laughing )... so response needed PLEASE... thanks bro's
Back to top
toralf



Joined: 31 Jan 2005
Posts: 3841
Location: Bremen, Germany

PostPosted: Tue Mar 08, 2005 8:32 am    Post subject: Reply with quote

Where are you from? If you perfer german language, you can use it.

What do you really want to do?

Something like this?
Code:
ListOfFileNames =
ListOfFullPaths =
Loop, %ProgramFiles%\*.htm, , 1  ; Recurse into subfolders.
  {
    ListOfFileNames = %ListOfFileNames%|%A_LoopFileName%
    ListOfFullPaths = %ListOfFullPaths%|%A_LoopFileFullPath%
  }

;remove first pipe
StringTrimLeft,ListOfFileNames,ListOfFileNames,1
StringTrimLeft,ListOfFullPaths,ListOfFullPaths,1

StringSplit, ArrayOfFileNames, ListOfFileNames, |
StringSplit, ArrayOfFullPaths,ListOfFullPaths,|


Now you have each file name in a variable and the corresponding path in a other variable. The number at the end of both variable is the same.
The total number of variables (files) is in ArrayOfFileNames0.
_________________
Ciao
toralf
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Guest






PostPosted: Tue Mar 08, 2005 8:46 am    Post subject: Reply with quote

welll... thanks for the reply... i'll try if this one works... but i dont think that it'll do the trick... so what i wanna do ?... i'll try to make a bit more clearer:

i want to just type the NAME of the file to open it.... like if i've specified c:\test\*.*....and there is a file test.ahk(C:\test\test.ahk) in that folder ... i want to just type "test.ahk" to open it...
i think it is clear now..
Back to top
toralf



Joined: 31 Jan 2005
Posts: 3841
Location: Bremen, Germany

PostPosted: Tue Mar 08, 2005 8:51 am    Post subject: Reply with quote

If you serach through one file, you might do this:
Code:
LineCount = 0
Loop,Read,%File%
  {
    LineCount ++
    Line = %A_LoopReadLine%
    StringGetPos, OutputVar, Line, %SearchText%
    If ErrorLevel = 0
      FoundLine = %FoundLine%|%LineCount%
  }
;remove first pipe
StringTrimLeft,FoundLine,FoundLine,1

StringSplit, ArrayOfFoundLine, FoundLine, |

MsgBox, I found %ArrayOfFoundLine0% times the string "%SearchText%" in the file: %File%.`nIt is in Line :%FoundLine%

_________________
Ciao
toralf
Back to top
View user's profile Send private message Send e-mail Visit poster's website
toralf



Joined: 31 Jan 2005
Posts: 3841
Location: Bremen, Germany

PostPosted: Tue Mar 08, 2005 8:57 am    Post subject: Reply with quote

Ok, how about this?
Code:
Loop, %ArrayOfFileNames0%
  {
    FileName := ArrayOfFileNames%A_Index%
    FilePath := ArrayOfFullPaths%A_Index%
    StringGetPos, OutputVar, FileName, %UserInput%
    If ErrorLevel = 0
      FoundFile = %FoundFile%|%FilePath%%FileName%
  }
;remove first pipe
StringTrimLeft,FoundFile,FoundFile,1

StringSplit, ArrayOfFoundFile, FoundFile, |

If ArrayOfFoundFile0 > 1
  MsgBox, found more than one file, please be more specific
else if ArrayOfFoundFile = 1
  Run, %ArrayOfFoundFile1%
else
  MsgBox, No file found

_________________
Ciao
toralf
Back to top
View user's profile Send private message Send e-mail Visit poster's website
BoBo
Guest





PostPosted: Tue Mar 08, 2005 10:32 am    Post subject: Reply with quote

@ Guest (btw. boring nick Rolling Eyes)
Quote:
Where are you from?
Back to top
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