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 

Checking if some files exist...

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



Joined: 11 Nov 2005
Posts: 142

PostPosted: Thu Mar 09, 2006 3:00 am    Post subject: Checking if some files exist... Reply with quote

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
View user's profile Send private message
Veovis



Joined: 13 Feb 2006
Posts: 390
Location: Utah

PostPosted: Thu Mar 09, 2006 5:06 am    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail Visit poster's website
robiandi
Guest





PostPosted: Thu Mar 09, 2006 11:55 am    Post subject: Reply with quote

@Veovis: Thanks for this idea.
Back to top
PhiLho



Joined: 27 Dec 2005
Posts: 6721
Location: France (near Paris)

PostPosted: Thu Mar 09, 2006 12:09 pm    Post subject: Reply with quote

Veovis wrote:
<title>Untitled Document</title>
Shocked Confused Laughing
I see such titles sometime, while surfing on the Internet. Not always homepages, sometime serious corporate pages... Surprised
_________________
vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2")
Back to top
View user's profile Send private message Visit poster's website
Veovis



Joined: 13 Feb 2006
Posts: 390
Location: Utah

PostPosted: Thu Mar 09, 2006 6:07 pm    Post subject: Reply with quote

Laughing Picky, picky....

Shall I change it to "Titled Document" or what? Very Happy
_________________

"Power can be given overnight, but responsibility must be taught. Long years go into its making."
Back to top
View user's profile Send private message Send e-mail Visit poster's website
badmojo



Joined: 11 Nov 2005
Posts: 142

PostPosted: Fri Mar 10, 2006 2:42 am    Post subject: Reply with quote

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... Wink

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
View user's profile Send private message
Veovis



Joined: 13 Feb 2006
Posts: 390
Location: Utah

PostPosted: Fri Mar 10, 2006 4:52 am    Post subject: Reply with quote

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? Laughing
_________________

"Power can be given overnight, but responsibility must be taught. Long years go into its making."
Back to top
View user's profile Send private message Send e-mail Visit poster's website
badmojo



Joined: 11 Nov 2005
Posts: 142

PostPosted: Fri Mar 10, 2006 5:11 am    Post subject: Reply with quote

Thanks again Veovis... You're a lifesaver... Wink
Back to top
View user's profile Send private message
PhiLho



Joined: 27 Dec 2005
Posts: 6721
Location: France (near Paris)

PostPosted: Fri Mar 10, 2006 11:46 am    Post subject: Reply with quote

Anonymous (Veovis) wrote:
Quote:
<title>File Report</title>

Is that better PhiLho? Laughing

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! Razz).

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
View user's profile Send private message Visit poster's website
badmojo



Joined: 11 Nov 2005
Posts: 142

PostPosted: Mon Mar 13, 2006 7:05 am    Post subject: Reply with quote

wow, thanks PhiLho. your method makes the script more elegant... tks again to both, you & Veovis for taking such an interest in my request... Wink

best regards,
badmojo
Back to top
View user's profile Send private message
kapege.de



Joined: 07 Feb 2005
Posts: 186
Location: Munich, Germany

PostPosted: Mon Mar 13, 2006 7:53 am    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
Veovis



Joined: 13 Feb 2006
Posts: 390
Location: Utah

PostPosted: Mon Mar 13, 2006 8:05 pm    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail Visit poster's website
badmojo



Joined: 11 Nov 2005
Posts: 142

PostPosted: Tue Mar 14, 2006 2:31 am    Post subject: Reply with quote

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... Wink

anyway, tks kapege.de for pointing it out

best regards,
badmojo
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