Announcement

Collapse
No announcement yet.

Script to Remove Specific Characters

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Script to Remove Specific Characters

    Good Morning,
    I am quite new to scripting and need a bit of guidance please. I need to create a script which checks a number of text files which are located in various sub folders and removes any \ from within the text files. These files are created regularly by our systems so the script needs to be scheduled.

  • #2
    Re: Script to Remove Specific Characters

    This would be a great starting place

    Comment


    • #3
      Re: Script to Remove Specific Characters

      Script has been written now with some help and guidance from other forums.


      Originally posted by edpatterson View Post
      This would be a great starting place

      Comment


      • #4
        Re: Script to Remove Specific Characters

        Great,

        And do you mind sharing it with the audience of this forum?
        Caesar's cipher - 3

        ZKHQ BRX HYHQWXDOOB GHFLSKHU WKLV BRX ZLOO UHDOLVH LW ZDV D ZDVWH RI WLPH!

        SFX JNRS FC U6 MNGR

        Comment


        • #5
          Re: Script to Remove Specific Characters

          Const ForReading = 1
          Const ForWriting = 2

          Set objFSO = CreateObject("Scripting.FileSystemObject")
          ShowSubFolders objFSO.GetFolder("c:\0799\rs")
          Sub ShowSubFolders(Folder)

          for each file in folder.Files
          Set objTmp = objFSO.CreateTextFile("C:\0799\temp.dat")
          objTmp.Close

          Set objFile = objFSO.OpenTextFile(file.path, ForReading)
          strText = objFile.ReadAll
          objFile.Close

          strNewText = Replace(strText, "\", "")

          Set objFile = objFSO.OpenTextFile("C:\0799\temp.dat", ForWriting)
          objFile.WriteLine strNewText
          objFile.Close

          strLastFile = file.path
          objFSO.DeleteFile file.path
          objFSO.MoveFile "C:\0799\temp.dat", strLastFile
          next
          For Each SubFolder in Folder.SubFolders
          ShowSubFolders Subfolder
          next
          End sub

          Comment


          • #6
            Re: Script to Remove Specific Characters

            using GNU sed

            Code:
            @echo off
            for /F %%a in ('dir /b /s /a-d file*txt') do (
                    sed -i.bak "s/\\//g" %%a
            )

            Comment

            Working...
            X