Jump to content

Sorry..Ultra Newbie Question!


Recommended Posts

Hi all,

I only discovered AutoIt last Friday after buying "Windows Scripting Admin - Little Black Book".

I have a question that I'm sure has been asked a zillion times, but I can't find the answer - So please, can you guys help?

I have a files that I download by ftp several times daily. The filenames change each time, but have a standard formula (They are called aninvs????.NHA - Where the ???? changes each time)

I have used an InputBox to assign the filename to a variable ($filename), and I would like to use AutoIt to open up my ftp script file and replace the previous filename with the new one.

eg the script looks like this:

open 10.100.1.25

username

password

cd /usr4/hcne/mdspool

lcd c:\ftp

bin

mget adinvs0101.NHA

bye

I would like to change the line "mget adinvs0101.NHA" to "mget $adinvs????.NHA" (based on whatever is returned by the $filename variable.)

How can I modify the script to change that one line in the script? I presume I need to use FileOpen & StringReplace to achieve this, but can't figure out how.

Hope you can help!

Steve

Link to comment
Share on other sites

Hi.

I do not have the whole answer to what you are trying to do. But here is some code from one of my scripts which may help get you further down the road.

I haven't had a reason or need to read a file yet, so you are on your own on that one.

Here isAutoit code which will write a variable to a new file:

;*************************

; Assign filename

$ofilnam="c:\data\test.log" ; Assign new filename to a variable

$myvariable = "Open New File" ; Create a string

FileOpen($ofilnam,2) ; Open a new file

FileWriteLine($ofilnam, $myvariable & @CRLF) ; Write output to file

FileWriteLine($ofilnam, " Today's Month is: " & @MON & @CRLF) ; Write more output

FileClose($ofilnam) ; close file

The output file should look like:

Open New File

Today's Month is: 03

The other thing you will need to do it parse and paste string elements.

$mystring = "aninvsXXXX.NHA"

$prefix = StringMid ($mystring, 1,6) ; should be [aninvs]

$NHA_ext = stringmid ($mystring, 11,4) ; should be [.NHA]

; Read in your new string to, say, $newstring

; then put it back into a new filename by:

$newoutfile = $prefix & $newstring & $NHA_ext

; Then write it out to your new file as described above.

Hope that helps.

-G

Link to comment
Share on other sites

If there's some sort of pattern to the "ADINVSxxxx.NHA" four "x" characters? (I.E. date, or time or something) that could be easy to code...or ... maybe they're the newest files on the FTP server? You could get a file list and then download all files created after the last time the program was ran.

This could eliminate the need for input boxes.

Lofting the cyberwinds on teknoleather wings, I am...The Blue Drache

Link to comment
Share on other sites

Larry - You are a star! Thanks, mate, worked a treat :lmao:

i am too lazy to wait for you to try...

I would create a template file...

open 10.100.1.25
username
password
cd /usr4/hcne/mdspool
lcd c:\ftp
bin
mget adinvs????.NHA
bye

then...

$file = "c:\full path\to template\file here.txt"
$newfile = "c:\full path\to config\file here.txt"

$input = InputBox("gimme","gimme")

$buffer = FileRead($file,FileGetSize($file))

$buffer = StringReplace($buffer,"????",$input)

FileDelete($newfile)

FileWrite($newfile,$buffer)

<{POST_SNAPBACK}>

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...