Modify a windows batch program

  • Stav: Closed
  • Odměna: $15
  • Přijatých návrhů: 2
  • Vítěz: riffraff80

Instrukce k soutěži

The current program does the following two things to all .ts files in the same directory:
1.) It removes leading numbers in the format "nnn.nnn." from all .ts files in the same directory.
2.) It adds the creation date to the end of the filename.

With that, the file "138.000.Myfile.ts" becomes "Myfile_16.02.18.ts" (using the date format DD.MM.YY)

Modify this script the following way:
1.) Instead of the creation date, add the last modified date to the files
2.) Only rename *.ts files which start with numbers like this: "nnn.nnn."
3.) If a file can't be renamed this way, because a file like "Myfile_16.02.18.ts" already exists, add a trailing number to it, e.g. "Myfile_16.02.18_1.ts". Count up this number until it is possible to rename the file. Example: If the files "Myfile_16.02.18_2.ts" and "Myfile_16.02.18_2.ts" already exist, create the file "Myfile_16.02.18_3.ts"
4.) Add the path to be processed as an optional command line argument. This means, starting the batch program with "rename.bat" processes the files in the current folder whereas "rename.bat c:\temp\files" renames the files in the corresponding folder.

Below, you see the code of the current program.
The first working entry wins. Thank you!

_____________________________________________________________________________
@echo off
setlocal enabledelayedexpansion
set Ext=.ts
set ExtLen=3
for /f "skip=5 tokens=1,3*" %%a in ('dir /a-d /tc *%Ext%') do (
set Name=%%c
if /i "!Name:~-%ExtLen%!" neq "%Ext%" exit /b
call :TrimName
set Creation=%%a
ren "%%c" "!Name:~0,-%ExtLen%!_!Creation:~0,6!!Creation:~8,2!%Ext%"
)
:TrimName
for /f "tokens=1* delims=." %%i in ("!Name!") do (
echo %%i|findstr /r "^[0-9][0-9]*$">nul || exit /b
set Name=%%j
)
if "!Name!" neq "" goto :TrimName
pause

Doporučené dovednosti

Zpětná vazba od zaměstnavatele

“Fast, professional and cooperative. Thanks a lot!”

Profilový obrázek Tobiaszu, Switzerland.

Nejlepší návrhy této soutěže

Zobrazit více příspěvků

Veřejná nástěnka k vyjasnění projektu

  • Tobiaszu
    Pořadatel soutěže
    • Před 6 let

    Okay guys. I increased the prize. Look forward to getting your inputs.

    • Před 6 let
  • chhamzatariq
    chhamzatariq
    • Před 6 let

    #increaseprize

    • Před 6 let

Jak začít se soutěžemi

  • Zadejte vaši soutěž

    Zveřejněte svou soutěž Rychlé a snadné

  • Získejte kupu návrhů

    Získejte spousty návrhů Z celého světa

  • Zvolte nejlepší návrh

    Zvolte nejlepší návrh Stáhněte si soubory - Je to snadné!

Zadejte soutěž nyní nebo se k nám připjte ještě dnes!