I have a logfile.txt that contains the following lines of text:
C:\VIDEO\My Video 1\My Video 1.mkv
C:\VIDEO\MyVideo2\MyVideo2.mkv
C:\VIDEO\My.Video.3\My.Video.3.mkv
and a folder C:\Temp that contains the files:
My Video 1.mkv
MyVideo2.mkv
My.Video.3.mkv
I need to use the logfile.txt to match the respective filename.mkv that is listed in the logfile, then move the file to its correct folder (as shown in the logfile).
E.g., My Video 1.mkv should be moved to C:\VIDEO\My Video 1\
The relevant folders already exist within C:\VIDEO and so do not require creation.
How can I write a batch file for this?
I am starting off right now with something like this, but I am now stuck:
@echo off
setlocal enableDelayedExpansion
set "logfile=C:\Temp\logfile.txt"
set "SourcePath=C:\Temp"
set "DestPath=C:\VIDEO"
if exist ..\%DestPath%\nul rd /s /q ..\%DestPath%
if not exist ..\%DestPath%\nul md ..\%DestPath%
for /f "delims=: tokens=1*" %%A in ('findstr /n "^" "%logfile%"') do move "%SourcePath%\%%a" "%DestPath%"
Can someone please assist?
DestPathis a variable, why are you referring to it asDestPathand not%DestPath%? (2) Given thatDestPathis a variable that refers to an absolute pathname (begins withC:\...), why are you saying..\DestPath? (3) Why are you usingfindstr? (4) Have you tried sayingdo echo %%Ato see what values%%Ais getting? – Scott - Слава Україні Jun 23 '19 at 03:56C:\VIDEOso do not require creation.” This would appear to be inconsistent with the fact that you’re destroying and re-creatingC:\VIDEO(a.k.a.%DestPath%) at the beginning of your script. (6) If the “log file” contains the names of the folders where you want the files to be moved to (and the relevant folders withinC:\VIDEOalready exist), then it seems that the batch file doesn’t need to know the destination path. (7) Loop index variables are case-sensitive, so%%ais not the same as%%A. – Scott - Слава Україні Jun 23 '19 at 15:14