Home > OS >  How to add a goto to a for loop
How to add a goto to a for loop

Time:01-03

I am working on a script that edits files and I am building a choice goto menu.

The script itself works fine, it reads from a file name that has ( ) in it. So my files are saved like this (1) filename.txt, (2) filename.txt ....(100) filename.txt
the content of the file has "times": 125489, saved in it, the script removes the 100 from the file name and does this "times": 100,

This is a small part of my content for my txt files it has a 4 indent space per line I believe the format is Json

  "aidr": 3.58,
  "nlpr": 0.5,
  "tafr": 0.5,
  "titp": 0.5,
  "trld": 0.0,
  "tssp": 0.5,
  "tssr": 0.5,
  "ttup": 0.5,
  "ttpp": 0.5,
  "times": 125,
  "Stamp": 125,
  "ppiid": 649,
  "otiid": 649,
  "apcid": 9,
  "orcid": 9,
  "jpcns": 0,
  "agpns": 0,
  "opcns": 0,
  "rppns": 0,

I recently found that when I merged all my single scripts together it slows down dramatically. Before the script processed 500 .txt files in 1 minute but now it takes 30 minutes.

My goal is to find a way to bring back the speed of this script.

I heard and read that adding a goto before and after the loop could make the script fast again.

@echo off

:Menu
ECHO ################################################################ 
echo.
ECHO                   1 - Script 1
ECHO                   2 - Script 2
ECHO                   3 - Script 3
ECHO                   4 - Script 4
ECHO                   5 - Script 5
ECHO                   100 - Script 100
echo.
set pass=
:: the choice command
set /p Mchoice=Make Your Choice: 
::goto choices
goto=:%Mchoice%
goto %goto%

:1
@ECHO Off
setlocal ENABLEDELAYEDEXPANSION

set "ToReplace1="times": "

SET "sourcedir=New folder 1"
SET "destdir=New fodler 2"

FOR /f "delims=" %%q IN ('dir /b /a-d "%sourcedir%\(*)*.txt"') DO (
(
  FOR /f "tokens=1 delims=()" %%j IN ("%%q") DO (
  for /F "tokens=1* delims=:" %%a in ('findstr /N "^" "%sourcedir%\%%q"') do (
   set "line=%%b"
   if defined line IF "%%b" neq "!line:times=!" CALL :Nums1 %%j
   echo(!line!
  )
 )

)>"           
  • Related