 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
badmojo
Joined: 11 Nov 2005 Posts: 142
|
Posted: Thu Mar 09, 2006 3:00 am Post subject: Checking if some files exist... |
|
|
Whenever I'm trouble-shooting a PC, I need to check whether some DLLs & OCXs are already in the system. I know that there are cmds like FileExist, IfExist and IfNotExist. Then I was thinking about an array-like variable that would store all the filenames that the script would check before returning true/false. But the problem is I'm not sure about how to set a list of DLLs/OCXs that would be loaded into the array when the script starts...
I was hoping that someone with the know-how could help me out here...
thanks in advance...
badmojo |
|
| Back to top |
|
 |
Veovis
Joined: 13 Feb 2006 Posts: 390 Location: Utah
|
Posted: Thu Mar 09, 2006 5:06 am Post subject: |
|
|
Whenever i want more than one line of output (more than a msgbox) i use html, cuase i can color it etc. This should do it:
| Code: | FileOfFiles = files.txt ;A file that has the list of files, NOTE: one file per line
Output = report.html
FileAppend,
(
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<body>
), %output%
i=0
Loop
{
i += 1
FileReadLine, file, %FileOfFiles%, %i%
if ErrorLevel <> 0
break
IfExist, %file%
FileAppend, <font color=#00FF00>%file% is present</font><br>, %output%
else
FileAppend, <font color=#FF0000>%file% is absent!!</font><br>, %output%
}
FileAppend,
(
</body>
</html>
), %output% |
You need a files.txt file that has something like this:
| Code: | These are random files
C:\Windows\PowerReg.dat
C:\Windows\NotePad.exe
C:\Windows\regopt.log
C:\Windows\regedit.exe |
_________________
"Power can be given overnight, but responsibility must be taught. Long years go into its making." |
|
| Back to top |
|
 |
robiandi Guest
|
Posted: Thu Mar 09, 2006 11:55 am Post subject: |
|
|
| @Veovis: Thanks for this idea. |
|
| Back to top |
|
 |
PhiLho
Joined: 27 Dec 2005 Posts: 6721 Location: France (near Paris)
|
Posted: Thu Mar 09, 2006 12:09 pm Post subject: |
|
|
| Veovis wrote: | | <title>Untitled Document</title> |
I see such titles sometime, while surfing on the Internet. Not always homepages, sometime serious corporate pages...  _________________
vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2") |
|
| Back to top |
|
 |
Veovis
Joined: 13 Feb 2006 Posts: 390 Location: Utah
|
Posted: Thu Mar 09, 2006 6:07 pm Post subject: |
|
|
Picky, picky....
Shall I change it to "Titled Document" or what?  _________________
"Power can be given overnight, but responsibility must be taught. Long years go into its making." |
|
| Back to top |
|
 |
badmojo
Joined: 11 Nov 2005 Posts: 142
|
Posted: Fri Mar 10, 2006 2:42 am Post subject: |
|
|
Thanks Veovis, the script works perfectly! I was wondering how to put the results on a GUI but your solution with HTML file is superb!, now I can just use some CSS coding to add background color & et. al...
| Quote: | | FileOfFiles = files.txt ;A file that has the list of files, NOTE: one file per line |
btw, is that script possible without any additional "files.txt" because I'd like to add the list straight in the script. e.g. the sequence of files can be broken by a comma or semi-colon...
thanks again...
best regards,
badmojo
Last edited by badmojo on Mon Mar 13, 2006 7:02 am; edited 1 time in total |
|
| Back to top |
|
 |
Veovis
Joined: 13 Feb 2006 Posts: 390 Location: Utah
|
Posted: Fri Mar 10, 2006 4:52 am Post subject: |
|
|
yuck.
I just typed up a reply and closed the window on accident.
Here we go again:
Having a String Parse will actually probably be better than a FileReadLine loop. Good Idea! Heres the Code:
| Code: | Output = report.html
FileAppend,
(
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>File Report</title>
</head>
<body>
), %output%
Files = C:\Windows\PowerReg.dat,C:\Windows\NotePad.exe,C:\Windows\regopt.log,C:\Windows\regedit.exe
Loop, Parse, Files, `,
{
IfExist, %A_LoopField%
FileAppend, <font color=#00FF00>%A_LoopField% is present</font><br>, %output%
else
FileAppend, <font color=#FF0000>%A_LoopField% is absent!!</font><br>, %output%
}
FileAppend,
(
</body>
</html>
), %output% |
| Quote: | | <title>File Report</title> |
Is that better PhiLho?  _________________
"Power can be given overnight, but responsibility must be taught. Long years go into its making." |
|
| Back to top |
|
 |
badmojo
Joined: 11 Nov 2005 Posts: 142
|
Posted: Fri Mar 10, 2006 5:11 am Post subject: |
|
|
Thanks again Veovis... You're a lifesaver...  |
|
| Back to top |
|
 |
PhiLho
Joined: 27 Dec 2005 Posts: 6721 Location: France (near Paris)
|
Posted: Fri Mar 10, 2006 11:46 am Post subject: |
|
|
| Anonymous (Veovis) wrote: | | Quote: | | <title>File Report</title> |
Is that better PhiLho?  |
Much better. Of course, my remark was more for pages on the Net than for internal/throwable pages. It was just an opportunity to rant against sloppy webmasters (not you! ).
Just a little remark (we are picky, aren't we?):
I would choose an illegal path character as filename separator: the comma is legal in a filename.
Files =
( Join| ; Or Join*, etc.
C:\Windows\PowerReg.dat
C:\Windows\NotePad.exe
C:\Windows\regopt.log
C:\Windows\regedit.exe
)
The continuation section is better if the list of files becomes long...
Don't forget to change the Loop Parse command... _________________
vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2") |
|
| Back to top |
|
 |
badmojo
Joined: 11 Nov 2005 Posts: 142
|
Posted: Mon Mar 13, 2006 7:05 am Post subject: |
|
|
wow, thanks PhiLho. your method makes the script more elegant... tks again to both, you & Veovis for taking such an interest in my request...
best regards,
badmojo |
|
| Back to top |
|
 |
kapege.de
Joined: 07 Feb 2005 Posts: 186 Location: Munich, Germany
|
Posted: Mon Mar 13, 2006 7:53 am Post subject: |
|
|
You shouldn't mix XML and the font-tag together. This is like mixing fire and water! Good browsers shows nothing or switching in her promiscous mode to show at least something.
If you are viewing your files only at your own computer this is enough:
| Code: | FileOfFiles = files.txt ;A file that has the list of files, NOTE: one file per line
Output = report.html
i=0
Loop
{
i += 1
FileReadLine, file, %FileOfFiles%, %i%
if ErrorLevel <> 0
break
IfExist, %file%
FileAppend, <font color=#00FF00>%file% is present</font><br>, %output%
else
FileAppend, <font color=#FF0000>%file% is absent!!</font><br>, %output%
}
|
_________________ Peter
Wisenheiming for beginners: KaPeGe (German only, sorry) |
|
| Back to top |
|
 |
Veovis
Joined: 13 Feb 2006 Posts: 390 Location: Utah
|
Posted: Mon Mar 13, 2006 8:05 pm Post subject: |
|
|
That top section was just copied from a blank DreamWeaver 8 document, so alot of it is probably uneeded, but it works, so... _________________
"Power can be given overnight, but responsibility must be taught. Long years go into its making." |
|
| Back to top |
|
 |
badmojo
Joined: 11 Nov 2005 Posts: 142
|
Posted: Tue Mar 14, 2006 2:31 am Post subject: |
|
|
| Veovis wrote: | | That top section was just copied from a blank DreamWeaver 8 document, so alot of it is probably uneeded, but it works, so... |
yes, i understand that it was meant as an example... anyway i had modified them to include CSS formatting and it works very well. of course, it's not for mass distribution...
anyway, tks kapege.de for pointing it out
best regards,
badmojo |
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|