Jump to content
Sign in to follow this  
Sam1el

Help with a parse/write

Recommended Posts

Sam1el

I've tried to write as much of my script as possible without asking for help but i'm stuck. I've searched the forums for my answer and read the help files but not totally sure how to go about my final step.

THe code reads a file in a specified drive and writes a log to a server.

What I need to add is, I need it to look for a specific word and then write the file if the word is present and not write the file if it isn't. I am sure it's a simple if/elsif and exit but not sure how to approach it.

here's a snippet.

Select
Case @OSVersion = "WIN_XP"
  If FileExists("C:\Documents and Settings\All Users\Application Data\DassaultSystemes\CATEnv\Teamcenter_Integration_for_CATIAV5.txt") Then
   FileReadLine('C:\Documents and Settings\All Users\Application Data\DassaultSystemes\CATEnv\Teamcenter_Integration_for_CATIAV5.txt', 10)
   $PCName = @ComputerName
   $file = FileOpen("\\server\SCCM_Logs\" & $PCName & "log.txt", 1)
   ; Write month/day @ time
   FileWrite($file, @MON & "/" & @MDAY & " @ " & @HOUR & ":" & @MIN & " - ")
   ; Write computer name along with text
   FileWrite($file, $PCName & " - " & "File Exists")
   ; go to next line
   FileWrite($file, @CRLF)
   FileClose($file)
   Exit
  EndIf
EndSelect

i'm super close to what I need. THe word i'm looking for is Amro if that'll help/

Share this post


Link to post
Share on other sites
water

Use function StringInStr. Something like

If StringInStr($string, $substring) > 0 Then FileWriteLine(...)


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-01-27 - Version 1.3.3.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites
Sam1el

Tried to implement this bit I may be missing something. It will parse and write my file according to my defined line but still wot print if it finds the text I'm looking for.

Share this post


Link to post
Share on other sites
FireFox

Hi,

Maybe this :

Select
Case @OSVersion = "WIN_XP"
If FileExists("C:Documents and SettingsAll UsersApplication DataDassaultSystemesCATEnvTeamcenter_Integration_for_CATIAV5.txt") Then
$sLineData = FileReadLine('C:Documents and SettingsAll UsersApplication DataDassaultSystemesCATEnvTeamcenter_Integration_for_CATIAV5.txt', 10)
If StringInStr($sLineData, "Amro") Then
$PCName = @ComputerName

$file = FileOpen("serverSCCM_Logs" & $PCName & "log.txt", 1)
; Write month/day @ time
FileWrite($file, @MON & "/" & @MDAY & " @ " & @HOUR & ":" & @MIN & " - ")
; Write computer name along with text
FileWrite($file, $PCName & " - " & "File Exists")
; go to next line
FileWrite($file, @CRLF)
FileClose($file)
EndIf
Exit
EndIf
EndSelect

Br, FireFox.


 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
Share on other sites
kylomas

Sam1el,

This script will only work if "Amro" exists on line 10 of the input file. Is this your intent?

kylomas


Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites
JohnOne

Tried to implement this bit I may be missing something. It will parse and write my file according to my defined line but still wot print if it finds the text I'm looking for.

Be clear, it writes what, and where?

Define print, and print what, and where?


AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Share this post


Link to post
Share on other sites
Sam1el

Yes! I would like it to only print the file if it finds the owrd amro and I woul dlike it appended to the name of the file. I am going to test the suggestions given. Thanks so much for your help and patience. caught a nasty staph infection on the business trip I just returned from and i'm half concious.

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  

×