Solved Simple CMD batch file edit

July 1, 2020 at 03:10:11
Specs: Windows 10
Hey guys, i'm tired trying to figure out but i just cant :/ I have this code:

@ECHO OFF
setlocal ENABLEDELAYEDEXPANSION

set "dest=C:\Users\marlo\Documents\Tower 5"

for /r %%a IN (*.mp4) do (
if exist "%dest%\%%~na%%~xa" (
for /f %%b in ('2^>nul dir "%dest%" /a-d/b/-o/-p/s^|find /v /c ""') do set "count=%%b"
if !count! EQU "0" set "count=1"
set /a continue=1
for /l %%c in (1,1,!count!) do (
if !continue! EQU 1 (
if not exist "%dest%\%%~na_%%c%%~xa" (
move /y "%%a" "%dest%\%%~na_%%c%%~xa"
set /a continue=0
)
)
)
) else (
move /y "%%a" "%dest%"
)
)

setlocal DISABLEDELAYEDEXPANSION

I need to modify and create 2 versions: one to move all mp4 files but exclude anything that has 'timelapse' anywhere in the filename and another version to move only mp4 files that have 'timelapse' anywhere in the filename.

Sorry for the hassle guys but appreciate any help =)
Thanks
Sel


See More: Simple CMD batch file edit


#1
July 1, 2020 at 09:52:03
i have a version that does both

this moves normal .mp4 files in the tower 5 dir to the no-timlapse dir:

@echo off&setlocal enabledelayedexpansion
cd "%userprofile%\documents\tower 5"
for /f "tokens=*" %%a in ('dir/a-d/b ^| findstr ".mp4"') do (
	set "test=%%a"
	if "!test!"=="!test:timelapse=!" (
		if not exist "%userprofile%\documents\tower 5\no-timelapse" (
			mkdir "%userprofile%\documents\tower 5\no-timelapse"
		)
		move "%%a" "%userprofile%\documents\tower 5\no-timelapse"
	)
)

this moves timelapse .mp4 files in the tower 5 dir to the timelapse dir:

@echo off&setlocal enabledelayedexpansion
cd "%userprofile%\documents\tower 5"
for /f "tokens=*" %%a in ('dir/a-d/b ^| findstr ".mp4"') do (
	set "test=%%a"
	if not "!test!"=="!test:timelapse=!" (
		if not exist "%userprofile%\documents\tower 5\timelapse" (
			mkdir "%userprofile%\documents\tower 5\timelapse"
		)
		move "%%a" "%userprofile%\documents\tower 5\timelapse"
	)
)

bonus (this does both at the same time):

@echo off&setlocal enabledelayedexpansion
cd "%userprofile%\documents\tower 5"
for /f "tokens=*" %%a in ('dir/a-d/b ^| findstr ".mp4"') do (
	set "test=%%a"
	if "!test!"=="!test:timelapse=!" (
		if not exist "no-timelapse" (
			mkdir "no-timelapse"
		)
		move "%%a" "no-timelapse"
	) else (
		if not exist "timelapse" (
			mkdir "timelapse"
		)
		move "%%a" "timelapse"
	)
)

my system specs: https://www.userbenchmark.com/UserR...


Reply ↓  Report •

#2
July 1, 2020 at 21:33:26
✔ Best Answer
Not too sure, but (run from root of directory of mp4 files):
::------------ begin batchscript
@echo off & setlocal
set rootwork="C:\Users\marlo\Documents\Tower 5"
:: CD to root working dir
pushd %rootwork%|| goto :eof
:: create subdirs, more validation needed, minimal done here 
for %%k in (timelapse no-timelapse) do (
md %%k||(
echo problem creating %rootwork%\%%k
goto :eof
)
)
for /f %%a in ('dir /b /s /a-d "*timelapse*.mp4') do move "%%~a" %rootwork%\timelapse
:: since the others already moved, all remaining mp4 qualify for no-timelapse
for /f %%a in ('dir /b /s /a-d *.mp4') do move "%%a" %rootwork%\no-timelapse

NOT tested.

message edited by nbrane


Reply ↓  Report •
Related Solutions


Ask Question