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

Author Topic: Batch file help  (Read 2958 times)

0 Members and 1 Guest are viewing this topic.

jaburmester

    Topic Starter


    Newbie

    • Experience: Beginner
    • OS: Windows 7
    Batch file help
    « on: February 23, 2017, 05:56:43 AM »
    @echo off
    setlocal disableDelayedExpansion
    cd C:\Documents and Settings\e51084\Desktop\New\Interest\f2

    Set "SrcDir=C:\Documents and Settings\e51084\Desktop\New\Interest\f2"
    Set "Mask=*.txt"
    Set "Line#=23"
    Set "LOfs=44"
    Set "Len=46"

    If /I Not "%CD%"=="%SrcDir%" Pushd "%SrcDir%"2>Nul&&(Set _=T)||Exit/B

    For /F "Tokens=1-2* Delims=:" %%A In ('FindStr/N "^" "%Mask%" 2^>Nul'
    ) Do If "%%B"=="%Line#%" If Not "%%~C"=="" (Set "Line=%%C"
        SetLocal EnableDelayedExpansion
        If Not "!Line:~%LOfs%,%Len%!"=="" (
           If Not Exist "!Line:~%LOfs%,%Len%!" (
       Pause
            Ren "%%A" "!Line:~%LOfs%,%Len%!"))
       Pause
        EndLocal)

    If "_"=="T" PopD


    The above searches a directory and renames fle name of all text files with some of the text within file.
    I now need some help in how to remove / from !Line:~%LOfs%,%Len%! as filenames cannot have /.

    If anyone can lead me in the right direction I would appreciate it.

    All help appreciated

    Thank you.

    Squashman



      Specialist
    • Thanked: 134
    • Experience: Experienced
    • OS: Other
    Re: Batch file help
    « Reply #1 on: February 23, 2017, 06:35:26 AM »
    How about you use BB CODE tags to format your code. Indentation of your code also makes it easier to read. Especially when you line up the closing parentheses with the command it is finishing.
    Code: [Select]
    @echo off
    setlocal disableDelayedExpansion
    cd C:\Documents and Settings\e51084\Desktop\New\Interest\f2

    Set "SrcDir=C:\Documents and Settings\e51084\Desktop\New\Interest\f2"
    Set "Mask=*.txt"
    Set "Line#=23"
    Set "LOfs=44"
    Set "Len=46"

    If /I Not "%CD%"=="%SrcDir%" Pushd "%SrcDir%"2>Nul&&(Set _=T)||Exit/B

    For /F "Tokens=1-2* Delims=:" %%A In ('FindStr/N "^" "%Mask%" 2^>Nul') Do (
    If "%%B"=="%Line#%" If Not "%%~C"=="" (
    Set "Line=%%C"
    SetLocal EnableDelayedExpansion
    If Not "!Line:~%LOfs%,%Len%!"=="" (
    If Not Exist "!Line:~%LOfs%,%Len%!" (
    Pause
    Ren "%%A" "!Line:~%LOfs%,%Len%!"
    )
    )
    Pause
    EndLocal
    )
    )

    If "_"=="T" PopD

    How about you also show us examples of the input files you are parsing.

    jaburmester

      Topic Starter


      Newbie

      • Experience: Beginner
      • OS: Windows 7
      Re: Batch file help
      « Reply #2 on: February 23, 2017, 06:53:16 AM »
      If you see scrip previously shown it take files like attachment and renames them in this case NICOS A. KYRATZIS AND/OR - 222222.txt but you cannot have / in  filename so I need a way to replace / with space.

      Hope this helps.

      Thank you for all help.

      [attachment deleted by admin to conserve space]

      Squashman



        Specialist
      • Thanked: 134
      • Experience: Experienced
      • OS: Other
      Re: Batch file help
      « Reply #3 on: February 23, 2017, 09:50:25 AM »
      You just need to add one line of code to replace the / with a space.
      Code: [Select]
      SET "Line=!Line:/= !"