I would like to create a .bat files that asks for a file extension and a path, then scans the directory and subfolders where the .bat file itself in located looking the all the files with the extension provided and moves them to the specified path while creating a .lnk in the original location.
For example the .bat would behave like this:
Enter file extension: mkv
Enter new path: e:\movies
Then it scans folder and subfolders of where the .bat file is located and move 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 want to copy also the original source structure to the new one. For example if I have a .mkv
file in d:\star trek\movie1\a.mkv
I would like to have e:\movies\star trek\movie1\a.mkv
and then d:\star trek\movie1\a.lnk
. The .lnk
should link to the moved file in folder on drive e:
.
Any ideas would be highly appreciated.
As a first step, I would like to create a simple batch that asks the user for an extension and then just lists all the files with that extension.
I wrote:
@echo off
set /p type= File type?
dir *.type > list.txt
But that doesn't work. Any suggestions?
I found some code here How to copy a directory structure but only include certain files (using windows batch files) and I'm just learning it. I've wrote down this simple adaptation but I don't understand why the last echo doesn't output what I intend, e.g. the whole destination path and file name. I must be doing something stupid I know!
@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
)
)