Spinner with filenames and total files on the same line.

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Matt Williamson
Posts: 82
Joined: 30 Dec 2013 10:16
Location: United States by the big waterfall

Spinner with filenames and total files on the same line.

#1 Post by Matt Williamson » 26 Feb 2015 13:15

I posted this on Stackoverflow but haven't had any feedback yet, so I thought I'd post it here too.

I'm trying to edit this code to show a spinner, the file name and total files moved updated for every hundred files moved. I have the spinner part worked out but I'm stuck getting the filenames and an accurate count. In this case I have 3,554 files but it stops at 3,500. I want to integrate it into another set of code that actually does the moving of the files. That code from Magoo is listed at the end of the post. So, to sum it all up, I just want a spinner that runs the whole time with the filenames showing on the same line as the spinner and the total number of files updating every 100 files and showing the correct total when all of the files have been processed.


Spinner Code

Code: Select all


@ECHO OFF
SETLOCAL
SET "sourcedir=C:\temp\xmls"
SET "spinChars=\|/-"
for /f %%a in ('"prompt $H&for %%b in (1) do rem"') do set "BS=%%a"
SET "filesmoved=0"
PUSHD "%sourcedir%"
For %%A in (*.xml) do set /a cnt+=1
Echo %cnt% files.
For /L %%I in (1,1,%cnt%) do (
    set /a filesmoved += 1, hundred = filesmoved %% 100
    setlocal enabledelayedexpansion
    if !hundred! equ 0 call :spinner
    endlocal
)

goto :EOF

:spinner
set "moved=%filesmoved%"
:spinner2
if %filesmoved% geq 400 set /a filesmoved -= 400 & goto :spinner2
set /a spinpos = filesmoved / 100
for /L %%I in (1,1,50) do set /P "=%BS%"<NUL
set /P "=Moving XML Files !spinChars:~%spinPos%,1!   %moved% Files moved"<NUL
goto :EOF


Batch move XML Files

Code: Select all

@ECHO OFF
SETLOCAL
SET "sourcedir=U:\sourcedir\t w o"
PUSHD "%sourcedir%"
FOR /f "tokens=1*delims=" %%a IN (
  'dir /b /a-d "%sourcedir%\*_*_*.xml" '
 ) DO SET "filename=%%a"&CALL :process

POPD

GOTO :EOF

:process
FOR /f "tokens=2,3,6delims=_" %%m IN ("%filename%") DO SET "date1=%%m"&SET "date2=%%n"&SET "whichdate=%%o"
IF DEFINED whichdate SET "date1=%date2%"
IF NOT DEFINED date2 GOTO :eof
ECHO(MD .\%date1:~0,4%\%date1:~4,2%
ECHO(MOVE "%filename%" .\%date1:~0,4%\%date1:~4,2%\
GOTO :EOF


And Here is the post that started it all.

jeb
Expert
Posts: 1063
Joined: 30 Aug 2007 08:05
Location: Germany, Bochum

Re: Spinner with filenames and total files on the same line.

#2 Post by jeb » 26 Feb 2015 13:40

I would add one more CALL :spinner after the end of your FOR loop.

Code: Select all

For /L %%I in (1,1,%cnt%) do (
    set /a filesmoved += 1, hundred = filesmoved %% 100
    setlocal enabledelayedexpansion
    if !hundred! equ 0 call :spinner
    endlocal
)
call :spinner


Of If you only want to call it when %cnt% is not a multiple of 100

Code: Select all

For /L %%I in (1,1,%cnt%) do (
    set /a filesmoved += 1, hundred = filesmoved %% 100
    setlocal enabledelayedexpansion
    if !hundred! equ 0 call :spinner
    endlocal
)
setlocal enabledelayedexpansion
if !hundred! NEQ 0 call :spinner
endlocal

Matt Williamson
Posts: 82
Joined: 30 Dec 2013 10:16
Location: United States by the big waterfall

Re: Spinner with filenames and total files on the same line.

#3 Post by Matt Williamson » 26 Feb 2015 14:07

Ahh, that's very good Jeb. Simple and concise. Now, can you help me integrate it into the code that actually moves the files? Thanks!

Matt

jeb
Expert
Posts: 1063
Joined: 30 Aug 2007 08:05
Location: Germany, Bochum

Re: Spinner with filenames and total files on the same line.

#4 Post by jeb » 26 Feb 2015 15:02

Something like this should work

Code: Select all

set cnt=0
FOR /f "tokens=1*delims=" %%a IN ('dir /b /a-d "%sourcedir%\*_*_*.xml" ' ) DO (
   set /a cnt+=1, hundred=cnt %% 100
   SET "filename=%%a"
   CALL :process
    setlocal enabledelayedexpansion
    if !hundred! equ 0 call :spinner
    endlocal
)

Matt Williamson
Posts: 82
Joined: 30 Dec 2013 10:16
Location: United States by the big waterfall

Re: Spinner with filenames and total files on the same line.

#5 Post by Matt Williamson » 26 Feb 2015 15:57

No such luck. Here is the code as I have it now. Did I miss anything?

Code: Select all

@ECHO OFF
SETLOCAL
SET "sourcedir=C:\temp\xmls"
SET "spinChars=\|/-"
for /f %%a in ('"prompt $H&for %%b in (1) do rem"') do set "BS=%%a"
SET "filesmoved=0"
PUSHD "%sourcedir%"
For %%A in (*.xml) do set /a cnt+=1
echo.
Echo %cnt% files.
echo.
FOR /f "tokens=1*delims=" %%a IN ('dir /b /a-d "%sourcedir%\*.xml" ' ) DO (
   set /a cnt+=1, hundred=cnt %% 100
   SET "filename=%%a"
   CALL :process
    setlocal enabledelayedexpansion
    if !hundred! equ 0 call :spinner
    endlocal
)
setlocal enabledelayedexpansion
if !hundred! NEQ 0 call :spinner
endlocal

goto :EOF

:spinner
set "moved=%filesmoved%"
:spinner2
if %filesmoved% geq 400 set /a filesmoved -= 400 & goto :spinner2
set /a spinpos = filesmoved / 100
for /L %%I in (1,1,50) do set /P "=%BS%"<NUL
set /P "=Moving XML Files !spinChars:~%spinPos%,1!   %moved% Files moved"<NUL
goto :EOF

:process
FOR /f "tokens=2,3,6delims=_" %%m IN ("%filename%") DO SET "date1=%%m"&SET "date2=%%n"&SET "whichdate=%%o"
IF DEFINED whichdate SET "date1=%date2%"
IF NOT DEFINED date2 GOTO :eof
::ECHO(MD .\%date1:~0,4%\%date1:~4,2%
::ECHO(MOVE "%filename%" .\%date1:~0,4%\%date1:~4,2%\
GOTO :EOF

Post Reply