Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: Problem using batch script  (Read 2806 times)

0 Members and 1 Guest are viewing this topic.

cellyn

    Topic Starter


    Newbie

    • Experience: Experienced
    • OS: Windows 7
    Problem using batch script
    « on: December 02, 2016, 03:01:21 AM »
    hi, i am new user of windows batch script. I am having problem to write a script to automate the repetitive programme. In the batch script, I need to the replace the input filename by another filename, can it be read directly from the filename itself or we do need to specify in the script? Because there are a lot of files, I can't specify one by one. Anyone can help?
    Thank you.

    Squashman



      Specialist
    • Thanked: 134
    • Experience: Experienced
    • OS: Other
    Re: Problem using batch script
    « Reply #1 on: December 02, 2016, 08:08:34 AM »
    Are you saying you have a list of file names you need to process with a program?

    Please post any code you have so far so we can understand the context of what you are trying to accomplish.

    cellyn

      Topic Starter


      Newbie

      • Experience: Experienced
      • OS: Windows 7
      Re: Problem using batch script
      « Reply #2 on: December 02, 2016, 08:54:37 PM »
      @echo off &setlocal
      set "search= "xyz"
      set "replace="abc"
      set "textfile=text123.txt"
      set "newfile="text321.txt"


      (for /f "delims=" %%i in ('findstr /n "search" "%textfile%"') do (
          set "line=%%i"
          setlocal enabledelayedexpansion
          set "line=%line:xyz=abc%"
          echo(%line%
          endlocal
      ))>"%newfile%"

      Thanks for your reply, Squashman. This is the code I am still trying on. Yes, I have a list of filenames which need to goes through the same process, so required to replace the filename in the batch one by one and produce a bunch of output files. Is it possible to do that? I've tried to replace just the filename in the script and save to a new file but it is failed. Can you help me on these? I have no idea how the batch script work and still trying hard to learn. Thank you.