mIRC Home    About    Download    Register    News    Help

Print Thread
#182436 09/08/07 04:04 PM
Joined: Dec 2002
Posts: 3,534
S
Hoopy frood
OP Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 3,534
I made a simple ShowDesktop alias that writes to (Show Desktop.scf) then runs the file.

Code:
alias ShowDesktop {
  var %x = $qt(Show Desktop.scf)
  write %x [Shell] $crlf Command=2 $crlf IconFile=explorer.exe,3 $& 
    $crlf [Taskbar] $crlf Command=ToggleDesktop
  run %x
  .remove %x
}


It works fine but my question is, would it be a better idea to check to see if it's a file and then run it or just simply delete the file that gets written to after every time I type the command? Also, would the above work for OS's earlier than XP I can only test on this XP machine and I want it to be able to work for everyone.

I have excluded the part to check whether or not

Thanks in advance. smile

Joined: Aug 2005
Posts: 1,052
L
Hoopy frood
Offline
Hoopy frood
L
Joined: Aug 2005
Posts: 1,052
Originally Posted By: SladeKraven
I made a simple ShowDesktop alias that writes to (Show Desktop.scf) then runs the file.

Code:
alias ShowDesktop {
  var %x = $qt(Show Desktop.scf)
  write %x [Shell] $crlf Command=2 $crlf IconFile=explorer.exe,3 $& 
    $crlf [Taskbar] $crlf Command=ToggleDesktop
  run %x
  .remove %x
}


It works fine but my question is, would it be a better idea to check to see if it's a file and then run it or just simply delete the file that gets written to after every time I type the command? Also, would the above work for OS's earlier than XP I can only test on this XP machine and I want it to be able to work for everyone.

I have excluded the part to check whether or not

Thanks in advance. smile


I would make a simple if $exists(%x) check to see if the code exist in the dir before writting a new file everytime.

Joined: Sep 2005
Posts: 2,630
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Sep 2005
Posts: 2,630
Check if it exists and run it. Use $isfile() though, not $exists()

hixxy #182689 13/08/07 11:27 AM
Joined: Dec 2002
Posts: 3,534
S
Hoopy frood
OP Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 3,534
Quote:
Check if it exists and run it. Use $isfile() though, not $exists()


Ah right, will do that. Cheers mate. smile

hixxy #182708 13/08/07 03:50 PM
Joined: Jan 2003
Posts: 2,125
Q
Hoopy frood
Offline
Hoopy frood
Q
Joined: Jan 2003
Posts: 2,125
Two things should be noted regarding $isfile() vs $exists():

$isfile() is useful if you want to make sure that when you /run %x, you won't get an Explorer window opening the folder %x that might happen to exist in the current folder.

However, if you assume that you can safely /write %x if $isfile() returns $false, you can run into problems, because if the folder %x exists in the current folder, you cannot create a file named %x there. In such cases, you'd need to use $isdir() or $exists().

What I'd do in this case is first check $exists(). If it returns $false, /write the file and /run it right away. Otherwise, also check $isfile(); if it returns $true, /run it right away, otherwise /write using another filename and /run it.

Of course, things can still go wrong if the file %x exists but contains other stuff than those .ini sections, but checking that is a bit too much; one might as well create a unique file anyway.

Last edited by qwerty; 13/08/07 03:59 PM.

Link Copied to Clipboard