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

Author Topic: Bat file, rename part of the file - it won't execute from task scheduler  (Read 1856 times)

0 Members and 1 Guest are viewing this topic.

smilingloki

    Topic Starter


    Newbie

    • Experience: Beginner
    • OS: Other
    Hi everyone,

    I have a windows 12 server,

    it downloads certain files, I have two problems, hopefully someone can help.

    I want to remove, "[eztv]" and i also want to remove,  "WEB" from the files before they are sent to another drive.

    the code i use - is this,

    @echo off
    setlocal enabledelayedexpansion
    set deletestring=[eztv]
    echo.

    for /f "delims==" %%F in ('dir /b ^| find "%deletestring%"') do (
       set oldfilename=%%F
       set newfilename=!oldfilename:%deletestring%=!
       Ren "!oldfilename!" "!newfilename!"
       )

    The problem is, i saved this as a .bat file and am running it from the same folder that the files are in - that works fine, it renames the file for the "[eztv]"

    Question, how do i include the "WEB" in to the above,

    Question, i have it set up correctly in task scheduler, but it shows as "running" and does not change the file name, neither does it stop running in the task scheduler either.
    I've checked permissions for the file and they are all fine - can't figure this one out.


    I am an absolute newbie at this and any help from you wonderful people would be most appreciated :D

    Regards
    SL
    « Last Edit: October 29, 2017, 10:59:43 PM by smilingloki »

    Salmon Trout



      Genius

      Thanked: 915
      • Yes
    • Computer: Specs
    • Experience: Experienced
    • OS: Other
    Re: Bat file, rename part of the file - it won't execute from task scheduler
    « Reply #1 on: October 30, 2017, 02:09:06 PM »
    Try this

    @echo off
    setlocal enabledelayedexpansion
    set deletestring1=[eztv]
    set deletestring2=WEB
    echo.

    for /f "delims==" %%F in ('dir /b ^| find "%deletestring1%"') do (
       set oldfilename=%%F
       set newfilename=!oldfilename:%deletestring1%=!
       Ren "!oldfilename!" "!newfilename!"
       )

    for /f "delims==" %%F in ('dir /b ^| find "%deletestring2%"') do (
       set oldfilename=%%F
       set newfilename=!oldfilename:%deletestring2%=!
       Ren "!oldfilename!" "!newfilename!"
       )



    Geek-9pm


      Mastermind
    • Geek After Dark
    • Thanked: 961
      • Gekk9pm bnlog
    • Certifications: List
    • Computer: Specs
    • Experience: Expert
    • OS: Windows XP
    Re: Bat file, rename part of the file - it won't execute from task scheduler
    « Reply #2 on: October 30, 2017, 04:51:27 PM »
    Use of ! in place of % is documented here:
    https://www.computerhope.com/sethlp.htm   8)

    Find the place whee is says:
    Quote
    Delayed environment variable expansion allows you to use a different character (the exclamation mark) to expand environment variables at execution time. If delayed variable expansion is enabled, the above examples could be written as follows to work as intended:
    Code: [Select]
    set VAR=before
    if "%VAR%" == "before" (
    set VAR=after
    if "!VAR!" == "after" @echo If you see this, it worked
    )

    set LIST=
    for %i in (*) do set LIST=!LIST! %i
    echo %LIST%

    smilingloki

      Topic Starter


      Newbie

      • Experience: Beginner
      • OS: Other
      Re: Bat file, rename part of the file - it won't execute from task scheduler
      « Reply #3 on: October 30, 2017, 06:59:37 PM »
      Try this

      @echo off
      setlocal enabledelayedexpansion
      set deletestring1=[eztv]
      set deletestring2=WEB
      echo.

      for /f "delims==" %%F in ('dir /b ^| find "%deletestring1%"') do (
         set oldfilename=%%F
         set newfilename=!oldfilename:%deletestring1%=!
         Ren "!oldfilename!" "!newfilename!"
         )

      for /f "delims==" %%F in ('dir /b ^| find "%deletestring2%"') do (
         set oldfilename=%%F
         set newfilename=!oldfilename:%deletestring2%=!
         Ren "!oldfilename!" "!newfilename!"
         )



      Thanks Salmon - that works for editing the files, but when i use the task scheduler - for some reason it does not work?
      it says that it has run, but it just doesnt edit the file and take out the  [eztv]

      Is there something wrong with the file when it runs the .bat  by the task scheduler?

      Regards

      SL