?
Solved

I need a program to open a file name ProdSNA.acg where ever it is on a PC and then find and replace the following text

Posted on 2003-03-22
12
Medium Priority
?
185 Views
Last Modified: 2010-05-01
I need it to open the file where ever it may be on a machine. Each version is in a different directory so it will need to search a hard drive for it. The textI need it to find and replace is as follows.

Find

DEST_ADDRESS=4000113000004

Replace with

DEST_ADDRESS=10005AD1C45A

then I need it to save the file to the location it opened it

I would just use the API edit it but the file is not like a regular INI file. Here is what it looks like.



*TSMon Oct 28 13:34:04 2002
NODE=(
     ANYNET_SUPPORT=NONE
     CP_ALIAS=@2D8
     DEFAULT_PREFERENCE=NATIVE
     DISCOVERY_SUPPORT=NO
     DLUR_SUPPORT=MULTI_SUBNET
     FQ_CP_NAME=BMCNET.@2D8
     NODE_ID=05D002D8
     NODE_TYPE=END_NODE
     REGISTER_WITH_CDS=1
     REGISTER_WITH_NN=1
)
PORT=(
     PORT_NAME=LANX_04
     ACTIVATION_DELAY_TIMER=30
     DELAY_APPLICATION_RETRIES=1
     DLC_DATA=00000000000004
     DLC_NAME=LAN
     IMPLICIT_CP_CP_SESS_SUPPORT=1
     IMPLICIT_DEACT_TIMER=0
     IMPLICIT_DSPU_SERVICES=NONE
     IMPLICIT_HPR_SUPPORT=1
     IMPLICIT_LIMITED_RESOURCE=NO
     IMPLICIT_LINK_LVL_ERROR=0
     LINK_STATION_ROLE=NEGOTIABLE
     MAX_ACTIVATION_ATTEMPTS=10
     MAX_IFRM_RCVD=8
     MAX_RCV_BTU_SIZE=32767
     PORT_TYPE=SATF
     RETRY_LINK_ON_DISCONNECT=1
     RETRY_LINK_ON_FAILED_START=1
     RETRY_LINK_ON_FAILURE=1
     PORT_LAN_SPECIFIC_DATA=(
          ACK_DELAY=100
          ACK_TIMEOUT=3000
          ADAPTER_NUMBER=9999
          BUSY_STATE_TIMEOUT=60
          IDLE_STATE_TIMEOUT=30
          LOCAL_SAP=04
          MAX_RETRY=10
          OUTSTANDING_TRANSMITS=16
          POLL_TIMEOUT=3000
          POOL_SIZE=16
          REJECT_RESPONSE_TIMEOUT=30
          TEST_RETRY_INTERVAL=8
          TEST_RETRY_LIMIT=5
          XID_RETRY_INTERVAL=8
          XID_RETRY_LIMIT=5
     )
)
PORT=(
     PORT_NAME=LANX_08
     ACTIVATION_DELAY_TIMER=30
     DELAY_APPLICATION_RETRIES=1
     DLC_DATA=00000000000008
     DLC_NAME=LAN
     IMPLICIT_CP_CP_SESS_SUPPORT=1
     IMPLICIT_DEACT_TIMER=0
     IMPLICIT_DSPU_SERVICES=NONE
     IMPLICIT_HPR_SUPPORT=1
     IMPLICIT_LIMITED_RESOURCE=NO
     IMPLICIT_LINK_LVL_ERROR=0
     LINK_STATION_ROLE=NEGOTIABLE
     MAX_ACTIVATION_ATTEMPTS=10
     MAX_IFRM_RCVD=8
     MAX_RCV_BTU_SIZE=32767
     PORT_TYPE=SATF
     RETRY_LINK_ON_DISCONNECT=1
     RETRY_LINK_ON_FAILED_START=1
     RETRY_LINK_ON_FAILURE=1
     PORT_LAN_SPECIFIC_DATA=(
          ACK_DELAY=100
          ACK_TIMEOUT=3000
          ADAPTER_NUMBER=9999
          BUSY_STATE_TIMEOUT=60
          IDLE_STATE_TIMEOUT=30
          LOCAL_SAP=08
          MAX_RETRY=10
          OUTSTANDING_TRANSMITS=16
          POLL_TIMEOUT=3000
          POOL_SIZE=16
          REJECT_RESPONSE_TIMEOUT=30
          TEST_RETRY_INTERVAL=8
          TEST_RETRY_LIMIT=5
          XID_RETRY_INTERVAL=8
          XID_RETRY_LIMIT=5
     )
)
LINK_STATION=(
     LS_NAME=LINK0000
     ACTIVATE_AT_STARTUP=1
     ACTIVATION_DELAY_TIMER=-1
     ADJACENT_NODE_TYPE=SUBAREA_LEN
     AUTO_ACTIVATE_SUPPORT=0
     CP_CP_SESS_SUPPORT=1
     DEFAULT_NN_SERVER=0
     DELAY_APPLICATION_RETRIES=0
     DEST_ADDRESS=4000113000004
     DISABLE_REMOTE_ACT=0
     DSPU_SERVICES=NONE
     ETHERNET_FORMAT=1
     FQ_ADJACENT_CP_NAME=BMCNET.LINK0000
     HPR_LINK_LVL_ERROR=0
     HPR_SUPPORT=0
     INHERIT_PORT_RETRY_PARMS=1
     LIMITED_RESOURCE=NO
     LINK_DEACT_TIMER=0
     LINK_STATION_ROLE=USE_ADAPTER_DEFAULTS
     MAX_ACTIVATION_ATTEMPTS=-1
     MAX_IFRM_RCVD=0
     MAX_SEND_BTU_SIZE=32767
     NODE_ID=05D002D8
     PORT_NAME=LANX_04
     PU_NAME=DIRPU000
     RETRY_LINK_ON_DISCONNECT=0
     RETRY_LINK_ON_FAILED_START=0
     RETRY_LINK_ON_FAILURE=0
     SOLICIT_SSCP_SESSION=1
     TG_NUMBER=0
     USE_DEFAULT_TG_CHARS=1
)
LINK_STATION=(
     LS_NAME=LINK0001
     ACTIVATE_AT_STARTUP=1
     ACTIVATION_DELAY_TIMER=-1
     ADJACENT_NODE_TYPE=SUBAREA_LEN
     AUTO_ACTIVATE_SUPPORT=0
     CP_CP_SESS_SUPPORT=1
     DEFAULT_NN_SERVER=0
     DELAY_APPLICATION_RETRIES=0
     DEST_ADDRESS=4000113000004
     DISABLE_REMOTE_ACT=0
     DSPU_SERVICES=NONE
     ETHERNET_FORMAT=0
     FQ_ADJACENT_CP_NAME=BMCNET.LINK0001
     HPR_LINK_LVL_ERROR=0
     HPR_SUPPORT=0
     INHERIT_PORT_RETRY_PARMS=1
     LIMITED_RESOURCE=NO
     LINK_DEACT_TIMER=0
     LINK_STATION_ROLE=USE_ADAPTER_DEFAULTS
     MAX_ACTIVATION_ATTEMPTS=-1
     MAX_IFRM_RCVD=0
     MAX_SEND_BTU_SIZE=32767
     NODE_ID=05D002D8
     PORT_NAME=LANX_08
     PU_NAME=DIRPU001
     RETRY_LINK_ON_DISCONNECT=0
     RETRY_LINK_ON_FAILED_START=0
     RETRY_LINK_ON_FAILURE=0
     SOLICIT_SSCP_SESSION=1
     TG_NUMBER=0
     USE_DEFAULT_TG_CHARS=1
)
MODE=(
     MODE_NAME=BLANK
     AUTO_ACT=0
     COMPRESSION=PROHIBITED
     COS_NAME=#CONNECT
     DEFAULT_RU_SIZE=1
     MAX_NEGOTIABLE_SESSION_LIMIT=256
     MAX_RU_SIZE_UPPER_BOUND=1024
     MIN_CONWINNERS_SOURCE=128
     PLU_MODE_SESSION_LIMIT=256
     RECEIVE_PACING_WINDOW=3
)
MODE=(
     MODE_NAME=#BATCH
     AUTO_ACT=0
     COMPRESSION=PROHIBITED
     COS_NAME=#BATCH
     DEFAULT_RU_SIZE=0
     MAX_NEGOTIABLE_SESSION_LIMIT=256
     MAX_RU_SIZE_UPPER_BOUND=2048
     MIN_CONWINNERS_SOURCE=128
     PLU_MODE_SESSION_LIMIT=256
     RECEIVE_PACING_WINDOW=20
)
MODE=(
     MODE_NAME=#BATCHSC
     AUTO_ACT=0
     COMPRESSION=PROHIBITED
     COS_NAME=#BATCHSC
     DEFAULT_RU_SIZE=1
     MAX_NEGOTIABLE_SESSION_LIMIT=256
     MAX_RU_SIZE_UPPER_BOUND=2048
     MIN_CONWINNERS_SOURCE=128
     PLU_MODE_SESSION_LIMIT=256
     RECEIVE_PACING_WINDOW=3
)
MODE=(
     MODE_NAME=#INTER
     AUTO_ACT=0
     COMPRESSION=PROHIBITED
     COS_NAME=#INTER
     DEFAULT_RU_SIZE=1
     MAX_NEGOTIABLE_SESSION_LIMIT=256
     MAX_RU_SIZE_UPPER_BOUND=4096
     MIN_CONWINNERS_SOURCE=128
     PLU_MODE_SESSION_LIMIT=256
     RECEIVE_PACING_WINDOW=20
)
MODE=(
     MODE_NAME=#INTERSC
     AUTO_ACT=0
     COMPRESSION=PROHIBITED
     COS_NAME=#INTERSC
     DEFAULT_RU_SIZE=1
     MAX_NEGOTIABLE_SESSION_LIMIT=256
     MAX_RU_SIZE_UPPER_BOUND=2048
     MIN_CONWINNERS_SOURCE=128
     PLU_MODE_SESSION_LIMIT=256
     RECEIVE_PACING_WINDOW=7
)
MODE=(
     MODE_NAME=QPCSUPP
     AUTO_ACT=0
     COMPRESSION=PROHIBITED
     COS_NAME=#CONNECT
     DEFAULT_RU_SIZE=1
     MAX_NEGOTIABLE_SESSION_LIMIT=52
     MAX_RU_SIZE_UPPER_BOUND=1024
     MIN_CONWINNERS_SOURCE=26
     PLU_MODE_SESSION_LIMIT=52
     RECEIVE_PACING_WINDOW=2
)
MODE=(
     MODE_NAME=QSERVER
     AUTO_ACT=0
     COMPRESSION=PROHIBITED
     COS_NAME=#CONNECT
     DEFAULT_RU_SIZE=1
     MAX_NEGOTIABLE_SESSION_LIMIT=64
     MAX_RU_SIZE_UPPER_BOUND=1024
     MIN_CONWINNERS_SOURCE=0
     PLU_MODE_SESSION_LIMIT=64
     RECEIVE_PACING_WINDOW=7
)
MODE=(
     MODE_NAME=SNASVCMG
     AUTO_ACT=0
     COMPRESSION=PROHIBITED
     COS_NAME=SNASVCMG
     DEFAULT_RU_SIZE=0
     MAX_NEGOTIABLE_SESSION_LIMIT=2
     MAX_RU_SIZE_UPPER_BOUND=512
     MIN_CONWINNERS_SOURCE=1
     PLU_MODE_SESSION_LIMIT=2
     RECEIVE_PACING_WINDOW=1
)
SHARED_FOLDERS=(
     CACHE_SIZE=256
)
VERIFY=(
     CFG_MODIFICATION_LEVEL=13
     CFG_VERSION_LEVEL=1
)
















0
Comment
Question by:donkellogg
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 8
  • 4
12 Comments
 
LVL 5

Expert Comment

by:Cimperiali
ID: 8193749
Option Explicit
'need four labels, a combobox,
'a commandbutton
'Three text boxes.
'I left original names of object, thus you can drop
'controls on form  and put this code and run after you
'setted a reference via menu ->project->references to
'"Microsoft Scripting Runtime"
'and the program will work...;-)
Private Fso As Scripting.FileSystemObject
Dim theTotalFounded As Long


Private Sub Form_Load()
   Dim theDrive As Scripting.Drive
   Label1.AutoSize = True
   Label2.AutoSize = True
   Label3.AutoSize = True
   Label4.AutoSize = True
   Label1.Caption = "Choose a Drive" 'this label is near the combobox
   Label2.Caption = "text to be replaced" 'this goes near first textbox
   Label3.Caption = "text thatreplace the previous" 'this goes near the second textbox
   Label4.Caption = "File Name" 'this goes near third textbox
   Text1.Text = "DEST_ADDRESS=4000113000004" 'default on load value of text1
   Text2.Text = "DEST_ADDRESS=10005AD1C45A" 'default on load value of text2
   Text3.Text = "ProdSNA.acg" 'default filename and extension to be found
   Command1.Caption = "Replace all"
   'fill combo with all drives
   Set Fso = New Scripting.FileSystemObject
   For Each theDrive In Fso.Drives
      'add only fixed drives or mapped fixed drives
      If (theDrive.DriveType And Fixed) Then
         Combo1.AddItem theDrive.DriveLetter
      End If
   Next
   Combo1.Text = Combo1.List(0) 'put first disk founded as actual value of combo
End Sub
Private Sub Command1_Click()
   screen.mousepointer = vbhourglass
   'start a recursive search throughout all disk
   theTotalFounded = 0
   Call SerachAndChange(Fso.GetFolder(Combo1.Text))
   screen.mousepointer = vbdefault
   MsgBox "Founded " & theTotalFounded & " " & Text3.Text & " files"
End Sub
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
   'free resources
   Set Fso = Nothing
End Sub
Private Sub SerachAndChange(theFolder As Scripting.Folder)
   Dim theFile As Scripting.File
   Dim theSubFolder As Scripting.Folder
   On Error Resume Next
   'first search for all file in current folder
   For Each theFile In theFolder.Files
      Doevents 'let the screen do not hang
      'beware of mistakes for protected files
      If Err.Number = 0 Then
         'case insensitive, as you cannot have two filenames
         'in same place with same name, regrardless of chars case
         If LCase(theFile.Name) = LCase(Text3.Text) Then
            'founded. Go to change it
            'record this to tell user how many
            theTotalFounded = theTotalFounded + 1
            Call ChangeFile(theFile.Path, theFile.Name)
         End If
      Else
         Err.Clear
      End If
   Next
   'now call this function recursively
   'be ware of errors in protected folders
   For Each theSubFolder In theFolder.SubFolders
      If Err.Number = 0 Then
         Call SerachAndChange(theSubFolder)
      Else
        Err.Clear
      End If
   Next
End Sub
Private Sub ChangeFile(theFilePath As String, theFileName As String)
Dim intFree As Integer
Dim fileText As String
'Be sure path ends with a "\"
If Right(theFilePath, 1) <> "\" Then
   theFilePath = theFilePath & "\"
End If
'get a freefile number
intFree = FreeFile
'open the file and read whole content
Open theFilePath & theFileName For Binary As #intFree
   ' read the string and close the file
    fileText = Space$(LOF(intFree))
    Get #intFree, , fileText
Close #intFree
'change all occurences of that string:
fileText = Replace(fileText, Text1.Text, Text2.Text, 1, -1, vbTextCompare) 'change this to vbBimaryVompare if you want a case sensitive match
'write back the file.
'You have many options, but as you cannot
'be sure everithing will go on fine, do not overwrite
'old file, but rename it adding a .Bak at its end
'and create a new one

Name theFilePath & theFileName As theFilePath & theFileName & ".Bak"
Open theFilePath & theFileName For Binary As #intFree
     Put #intFree, 1, fileText
Close #intFree
End Sub

0
 
LVL 5

Expert Comment

by:Cimperiali
ID: 8193754
A small mistake: add a  & ":" in first call
Private Sub Command1_Click()
   'start a recursive search throughout all disk
   theTotalFounded = 0
   'here the  <<& ":">> to be added at end:  
   Call SerachAndChange(Fso.GetFolder(Combo1.Text & ":"))
   MsgBox "Founded " & theTotalFounded & " " & Text3.Text & " files"
End Sub
0
 
LVL 5

Expert Comment

by:Cimperiali
ID: 8193845
Tested and found another bug. Here I post the correct code:
Option Explicit
'need four labels, a combobox,
'a commandbutton
'Three text boxes.
'I left original names of object, thus you can drop
'controls on form  and put this code and run after you
'setted a reference via menu ->project->references to
'"Microsoft Scripting Runtime"
'and the program will work...;-)
Private Fso As Scripting.FileSystemObject
Dim theTotalFounded As Long
Dim blnStop As Boolean

Private Sub Form_Load()
   Dim theDrive As Scripting.Drive
   Label1.AutoSize = True
   Label2.AutoSize = True
   Label3.AutoSize = True
   Label4.AutoSize = True
   Label1.Caption = "Choose a Drive" 'this label is near the combobox
   Label2.Caption = "text to be replaced" 'this goes near first textbox
   Label3.Caption = "text thatreplace the previous" 'this goes near the second textbox
   Label4.Caption = "File Name" 'this goes near third textbox
   Text1.Text = "DEST_ADDRESS=4000113000004" 'default on load value of text1
   Text2.Text = "DEST_ADDRESS=10005AD1C45A" 'default on load value of text2
   Text3.Text = "ProdSNA.acg" 'default filename and extension to be found
   Command1.Caption = "Replace all"
   'fill combo with all drives
   Set Fso = New Scripting.FileSystemObject
   For Each theDrive In Fso.Drives
      'add only fixed drives or mapped fixed drives
      If (theDrive.DriveType And Fixed) Then
         Combo1.AddItem theDrive.DriveLetter
      End If
   Next
   Combo1.Text = Combo1.List(0) 'put first disk founded as actual value of combo
End Sub
Private Sub Command1_Click()
   Screen.MousePointer = vbHourglass
   'start a recursive search throughout all disk
   theTotalFounded = 0
   Call SerachAndChange(Fso.GetFolder(Combo1.Text & ":\"))
   Screen.MousePointer = vbDefault
   MsgBox "Founded " & theTotalFounded & " " & Text3.Text & " files"
End Sub
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
   'stop recurse
   blnStop = True
   'free resources
   Set Fso = Nothing
End Sub
Private Sub SerachAndChange(theFolder As Scripting.Folder)
   Dim theFile As Scripting.File
   Dim theSubFolder As Scripting.Folder
   On Error Resume Next
   'first search for all file in current folder
   For Each theFile In theFolder.Files
      If blnStop Then Exit Function
      DoEvents
      'beware of mistakes for protected files
      If Err.Number = 0 Then
         'case insensitive, as you cannot have two filenames
         'in same place with same name, regrardless of chars case
         If LCase(theFile.Name) = LCase(Text3.Text) Then
            'founded. Go to change it
            'record this to tell user how many
            theTotalFounded = theTotalFounded + 1
            Call ChangeFile(theFile.Path, theFile.Name)
         End If
      Else
         Err.Clear
      End If
   Next
   'now call this function recursively
   'be ware of errors in protected folders
   Debug.Print theFolder.Name
   For Each theSubFolder In theFolder.SubFolders
      If blnStop Then Exit Function
      If Err.Number = 0 Then
         
         Call SerachAndChange(theSubFolder)
      Else
        Err.Clear
      End If
   Next
End Sub
Private Sub ChangeFile(theFilePath As String, theFileName As String)
Dim intFree As Integer
Dim fileText As String
'Be sure path ends with a "\"
If Right(theFilePath, 1) <> "\" Then
   theFilePath = theFilePath & "\"
End If
'get a freefile number
intFree = FreeFile
'open the file and read whole content
Open theFilePath & theFileName For Binary As #intFree
   ' read the string and close the file
    fileText = Space$(LOF(intFree))
    Get #intFree, , fileText
Close #intFree
'change all occurences of that string:
fileText = Replace(fileText, Text1.Text, Text2.Text, 1, -1, vbTextCompare) 'change this to vbBimaryVompare if you want a case sensitive match
'write back the file.
'You have many options, but as you cannot
'be sure everithing will go on fine, do not overwrite
'old file, but rename it adding a .Bak at its end
'and create a new one

Name theFilePath & theFileName As theFilePath & theFileName & ".Bak"
Open theFilePath & theFileName For Binary As #intFree
     Put #intFree, 1, fileText
Close #intFree
End Sub

0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 5

Expert Comment

by:Cimperiali
ID: 8193856
I am becoming old...I put "exit function" instead of "exit sub"...;-)
0
 
LVL 5

Expert Comment

by:Cimperiali
ID: 8194561
Did I tell you I am becoming old?...
If LCase(theFile.Name) = LCase(Text3.Text) Then
            'founded. Go to change it
            'record this to tell user how many
            theTotalFounded = theTotalFounded + 1
            Call ChangeFile(theFile.Path, theFile.Name)
            'as you cannot have twice same name in same dir,
            'exit this cycle
            Exit For  '<---Add this line!
         End If
0
 

Author Comment

by:donkellogg
ID: 8215634
I'll test the code tonight. I just found something else out. We don't know what the ACG file name is, it could be anything and anywhere on the hard drive. Also MS have .acg for OFfice so somehow the program needs to file all the ACG files and Exclude the MS Office ones.
0
 
LVL 5

Expert Comment

by:Cimperiali
ID: 8216328
Acg reminds me AS400 machine...
0
 

Author Comment

by:donkellogg
ID: 8220173
IBM PC3270 is what this is for we are converting from a TOKEN Ring host to a ETHERNET Host the bridge is messed up.
0
 
LVL 5

Accepted Solution

by:
Cimperiali earned 400 total points
ID: 8223417
Thus that file may be an Ascii one...
Does the code work fine for you?  
0
 

Author Comment

by:donkellogg
ID: 8231841
Yep the file is in standard ASCII format from what I can see. I tried the above code and it does not seem to find the ACG file. I confirmed it's name and it matches the search in the code.
0
 

Author Comment

by:donkellogg
ID: 8250456
This looks like a good start to what I need. Thank you for all the help. May I contact you if I have other questions related to the code?
0
 
LVL 5

Expert Comment

by:Cimperiali
ID: 8251654
Post here, and I will be notified by mail. I am a bit busy, but I will find the time to come here and see if I can help.
Now, to test the code I gave you, copy the file you're looking for in "C:\", put breakpoint at beginning of
Private Sub SerachAndChange(theFolder As Scripting.Folder)
and from ide start the search for that file.
As program enter the debug mode, go step by step to see if it find it.
By the way: you can comment the second errhandling (mistake may be there):
  'now call this function recursively
  'be ware of errors in protected folders
  For Each theSubFolder In theFolder.SubFolders
     'catch only mistakes for file reading, not for foldres
     'or you might skip one or more good folder...
     'If Err.Number = 0 Then
        Call SerachAndChange(theSubFolder)
     'Else
     '  Err.Clear
     'End If
  Next

0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question