Sign in to follow this  
Followers 0
YFNCG

Newbie Question

14 posts in this topic

I just stumbled across this gem of a program and WOW is all I can say. I am a system administrator and the possibilities this opens up for automating repetitve tasks is awesomw.

I am trying to write several scripts at the moment that will check for the existence of a particular "key file" and then perfom some file manipulation if the file is found. If the file is not found, for instance the first time the script is run, I need to be able to create an empty text file with a certain name in a particular place on the local hard drive. I have been unable to figure out how to create such a file from within a script. Any help will be appreciated.

Thanks.

JW

Share this post


Link to post
Share on other sites



Look at _FileCreate in the helpfile/documentation. That should be what your are looking for. Also, look at FileFindFirstFile and FileFindNextFile to help you look for the files.


_____________________________________________________"some people live for the rules, I live for exceptions"Wallpaper Changer - Easily Change Your Windows Wallpaper

Share this post


Link to post
Share on other sites

OK I took a look at the _FileCreate and I think I understand how it works. I have completed my script but when I try to run it nothing happens. I am planning to compile this and send it out to my users as an aid in troubleshooting network connectivity. Here is the script code:

$TARGET = INPUTBOX("PING TARGET ENTRY", "Please enter the Hostname or URL you need to PING:", "", " M",)

;

If NOT FileExists ( @WindowsDir\"ip.txt" ) then

#include

_FileCreate(@WindowsDir\"ip.txt") ; Make a throwaway file to avoid error on first run

Endif

SplashTextOn("Information on Ping Request", "Please be patient ! , The Ping of %TARGET% is running. Results will display shortly.")

Sleep, 2000

FileDelete (@WindowsDir\ip.txt)

Sleep, 2000

Ping -n=5 %TARGET% >> @WindowsDir\ip.txt ,,hide

Sleep, 10000

SplashOff

Run, notepad @WindowsDir\ip.txt

Sleep, 2000

WinSetState(ip.txt - Notepad, "",@SW_MAXIMIZE)

Exit

ANy idease as to why this will not work?

Thanks again.

Share this post


Link to post
Share on other sites

OK I took a look at the _FileCreate and I think I understand how it works. I have completed my script but when I try to run it nothing happens. I am planning to compile this and send it out to my users as an aid in troubleshooting network connectivity. Here is the script code:

$TARGET = INPUTBOX("PING TARGET ENTRY", "Please enter the Hostname or URL you need to PING:", "", " M",)

;

If NOT FileExists ( @WindowsDir\"ip.txt" ) then

#include

_FileCreate(@WindowsDir\"ip.txt") ; Make a throwaway file to avoid error on first run

Endif

SplashTextOn("Information on Ping Request", "Please be patient ! , The Ping of %TARGET% is running. Results will display shortly.")

Sleep, 2000

FileDelete (@WindowsDir\ip.txt)

Sleep, 2000

Ping -n=5 %TARGET% >> @WindowsDir\ip.txt ,,hide

Sleep, 10000

SplashOff

Run, notepad @WindowsDir\ip.txt

Sleep, 2000

WinSetState(ip.txt - Notepad, "",@SW_MAXIMIZE)

Exit

ANy idease as to why this will not work?

Thanks again.

:D

Are you using AutoItv2 and Not AutoItv3?

Either way, you delete the file you want to ping before you ping it.


[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

:D

Are you using AutoItv2 and Not AutoItv3?

Either way, you delete the file you want to ping before you ping it.

Using v3. I thought that the IP.TXT file was simply the file where the output of the ping process would be re-directed to. At least that is the intention. The IP address or hostname to ping should come from the InputBox variable $TARGET.

Share this post


Link to post
Share on other sites

Using v3. I thought that the IP.TXT file was simply the file where the output of the ping process would be re-directed to. At least that is the intention. The IP address or hostname to ping should come from the InputBox variable $TARGET.

If you are using V3 I suggest you look at the help file for the correct syntax for Run & Sleep. You will also need to change your Ping command.


Get Beta versions Here Get latest SciTE editor Here AutoIt 1-2-3 by Valuater - A great starting point.

Time you enjoyed wasting is not wasted time ......T.S. Elliot
Suspense is worse than disappointment................Robert Burns
God help the man who won't help himself, because no-one else will...........My Grandmother

Share this post


Link to post
Share on other sites

If your using V3, then your syntax is completely wrong on your function calls.

Sleep, 2000 = Sleep(2000) / Run, notepad @WindowsDir\ip.txt = Run('notepade.exe ' & '"' & @WindowsDir & '\ip.txt' & '"') etc... the Ping is wrong too, where did you get your syntaxing from out of curiousity?


[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

If your using V3, then your syntax is completely wrong on your function calls.

Sleep, 2000 = Sleep(2000) / Run, notepad @WindowsDir\ip.txt = Run('notepade.exe ' & '"' & @WindowsDir & '\ip.txt' & '"') etc... the Ping is wrong too, where did you get your syntaxing from out of curiousity?

Sorry about that. Some of the syntaxt came from a v2 sample script. I have made some modifications but when I run the script nothing happens. No inputbox no error message. Here is the edited text:

$TARGET = INPUTBOX("PING TARGET ENTRY", "Please enter the Hostname or URL you need to PING:", "", " M",)

;

If NOT FileExists ( @WindowsDir\"ip.txt" ) then

#include

_FileCreate(@WindowsDir\"ip.txt") ; Make a throwaway file to avoid error on first run

Endif

SplashTextOn("Information on Ping Request", "Please be patient ! , The Ping of %TARGET% is running. Results will display shortly.")

Sleep (2000)

_RunDOS (Ping -n=5 %TARGET%) > @WindowsDir\"ip.txt"

Sleep (10000)

SplashOff

Run (notepad.exe, @WindowsDir\"ip.txt")

WinSetState(ip.txt - Notepad, "",@SW_MAXIMIZE)

Exit

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

No I was using ConText which has AutoIt highlighters as well. I am downloading SciTe as I type.

This is what I see in SciTe but I am not sure what is wrong:

$TARGET = INPUTBOX("PING TARGET ENTRY", "Please enter the Hostname or URL you need to PING:", "", " M",)

;

If NOT FileExists ( @WindowsDir\"ip.txt" ) then

#include

_FileCreate(@WindowsDir\"ip.txt") ; Make a throwaway file to avoid error on first run

Endif

SplashTextOn("Information on Ping Request", "Please be patient ! , The Ping of %TARGET% is running. Results will display shortly.")

Sleep (2000)

_RunDOS (Ping -n=5 %TARGET%) > @WindowsDir\"ip.txt"

Sleep (10000)

SplashOff

Run (notepad.exe, @WindowsDir\"ip.txt")

WinSetState(ip.txt - Notepad, "",@SW_MAXIMIZE)

Exit

Edited by YFNCG

Share this post


Link to post
Share on other sites

I am feeling generous, study and learn

#include <File.au3>
#include <Process.au3>

$TARGET = INPUTBOX("PING TARGET ENTRY", "Please enter the Hostname or URL you need to PING:")
;
If NOT FileExists ( @WindowsDir & "\ip.txt" ) then

_FileCreate(@WindowsDir & "\ip.txt"); Make a throwaway file to avoid error on first run
Endif

SplashTextOn("Information on Ping Request", "Please be patient ! , The Ping of " & $TARGET & " is running. Results will display shortly.")
Sleep (2000)
_RunDOS ("Ping -n 5 " & $TARGET & ">>" & @WindowsDir & "\ip.txt")
Sleep (10000)
SplashOff ()
Run ("notepad.exe " & @WindowsDir & "\ip.txt")
WinSetState("ip.txt - Notepad", "",@SW_MAXIMIZE)
Exit


Get Beta versions Here Get latest SciTE editor Here AutoIt 1-2-3 by Valuater - A great starting point.

Time you enjoyed wasting is not wasted time ......T.S. Elliot
Suspense is worse than disappointment................Robert Burns
God help the man who won't help himself, because no-one else will...........My Grandmother

Share this post


Link to post
Share on other sites

I am feeling generous, study and learn

#include <File.au3>
#include <Process.au3>

$TARGET = INPUTBOX("PING TARGET ENTRY", "Please enter the Hostname or URL you need to PING:")
;
If NOT FileExists ( @WindowsDir & "\ip.txt" ) then

_FileCreate(@WindowsDir & "\ip.txt"); Make a throwaway file to avoid error on first run
Endif

SplashTextOn("Information on Ping Request", "Please be patient ! , The Ping of " & $TARGET & " is running. Results will display shortly.")
Sleep (2000)
_RunDOS ("Ping -n 5 " & $TARGET & ">>" & @WindowsDir & "\ip.txt")
Sleep (10000)
SplashOff ()
Run ("notepad.exe " & @WindowsDir & "\ip.txt")
WinSetState("ip.txt - Notepad", "",@SW_MAXIMIZE)
Exit
Thanks a million BD. I have a lot to learn about this powerful program but I usually pick thing up pretty quick. This forum is awesome. I have never had such a quick response from any other software forum before. It is really appreciated.

Share this post


Link to post
Share on other sites

Thanks a million BD. I have a lot to learn about this powerful program but I usually pick thing up pretty quick. This forum is awesome. I have never had such a quick response from any other software forum before. It is really appreciated.

This is a great place to start learning.


Get Beta versions Here Get latest SciTE editor Here AutoIt 1-2-3 by Valuater - A great starting point.

Time you enjoyed wasting is not wasted time ......T.S. Elliot
Suspense is worse than disappointment................Robert Burns
God help the man who won't help himself, because no-one else will...........My Grandmother

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0