I would like to create a .bat file that moves certain files (based on their extension) from a folder (with subfolders) to another disk preserving original tree structure while creating a .lnk in the original location to the moved files.
For example the .bat would behave like this:
File extension: mkv
Source path: d:\movies
Destination path e:\movies
The batch scans folder and subfolders and moves all the .mkv files to the new path, while creating a .lnk in the original source folder for each file that has been moved.
I found some code that I adapted to my purpose:
Code: Select all
@echo off
cls
setlocal enabledelayedexpansion
set SOURCE_DIR=K:\source
set DEST_DIR=K:\dest
set FILENAMES_TO_COPY=*.txt
for /R "%SOURCE_DIR%" %%F IN (%FILENAMES_TO_COPY%) do (
if exist "%%F" (
echo source: %%F
set FILE_DIR=%%~dpF
set FILE_INTERMEDIATE_DIR=!FILE_DIR:%SOURCE_DIR%=!
set FILE_NAME_EXT=%%~nxF
set FILE_DIR
set FILE_INTERMEDIATE_DIR
set FILE_NAME_EXT
xcopy /S /I /Y /V "%%F" "%DEST_DIR%!FILE_INTERMEDIATE_DIR!"
echo destination "%DEST_DIR%!FILE_INTERMEDIATE_DIR%FILE_NAME_EXT!"
pause
)
)
I want to check the destination (which I'll use as parameter for mklink) but the last echo
echo destination "%DEST_DIR%!FILE_INTERMEDIATE_DIR%FILE_NAME_EXT!"
This one gives me
destination "K:\dest"
I also tried
echo destination "%DEST_DIR%!FILE_INTERMEDIATE_DIR!FILE_NAME_EXT!"
This one give me
destination "K:\dest\FILE_NAME_EXT"
Not what I would like to have, ie the full destination path\filename.extension
I guess I'm just missing something trivial...
Any ideas would be highly appreciated.
Thank you very much,
Matt