Search large folders, copy found files, paste to new folder?
Posted: 20 Oct 2012 22:31
HI all! This question has come up before here : viewtopic.php?f=3&t=3285
I need to search a folder of 10,000 plus .wav files for 20 different files, 10 times a day. It gets tedious to say the least! If I could simply make a .txt file with the needed filenames, and run a .bat file to do the finding for me in the background, I could focus on more important elements of my task, like actually listening to the .wavs!
my file names will in 99.9% of cases be correct. the thread which already exists on this topic seems to have 10% incorrectly named file names, so has a way of discerning this built into the script. I do not need this element.
On this forum, and 1 other, I have found scripts which are designed to solve my problem.
this was made my Aacini on this forum.
elsewhere, I found
created by 'Duzzy'
and again,
also by duzzy.
I only learnt that this coding existed a few days ago. I have spent 8 hours watching tutorials trying to understand it, and am only finding basic ones, or little games.
What I need to learn is how to apply one of these scripts to MY context.
lets call my .txt file with the 20 .wavs 'breaks filenames world.txt'
the folder to search in is Z:\2011-MASTERS
The folder I would want them to go in, can be a new folder created by the script, that appears on the desktop
Hopefully my question is clear, if there is any info I have not provided that I need to please let me know! thanks in advance for any help! I would also be interested in some good tutorials which teach how I could create a script for this myself.
cheers all
Evan
I need to search a folder of 10,000 plus .wav files for 20 different files, 10 times a day. It gets tedious to say the least! If I could simply make a .txt file with the needed filenames, and run a .bat file to do the finding for me in the background, I could focus on more important elements of my task, like actually listening to the .wavs!
my file names will in 99.9% of cases be correct. the thread which already exists on this topic seems to have 10% incorrectly named file names, so has a way of discerning this built into the script. I do not need this element.
On this forum, and 1 other, I have found scripts which are designed to solve my problem.
Code: Select all
@echo off
setlocal EnableDelayedExpansion
cd /D "%~DP1"
set newFolder=%~N1
if not exist "%newFolder%" ECHO md "%newFolder%"
if exist "%newFolder%.log" del "%newFolder%.log"
set cutNumber=
set /P firstLine=< "%~NX1"
if "%firstLine:~0,1%" equ "1" (
if "%firstLine:~1,1%" equ "." (
set "cutNumber=. "
) else (
set "cutNumber=- "
)
)
for /F "usebackq delims=" %%a in ("%~NX1") do (
set "fileName=%%~Na"
if defined cutNumber (
set "fileName=!fileName:*%cutNumber%=!"
)
if exist "!fileName!.doc" (
ECHO copy "!fileName!.doc" "%newFolder%"
echo File "!fileName!.doc" copied
) else (
echo/
echo File not found: "!fileName!.doc"
call :getFileList "!fileName!"
if !n! gtr 0 (
if !n! equ 1 (
set i=1
) else (
set i=0
set /P "i=Enter the desired file number: "
)
if !i! gtr 0 (
call :setElem name=name[!i!]
ECHO copy "!name!" "%newFolder%"
echo File "!name!" copied
) else (
echo FILE NOT COPIED
echo File not found: "!fileName!.doc">> "%newFolder%.log"
)
) else (
echo I can't find any similar file...
)
)
)
if exist "%newFolder%.log" (
echo/
echo/
echo THESE FILES WERE NOT COPIED:
type "%newFolder%.log"
)
PAUSE
goto :EOF
:getFileList
set n=0
set "name=%~N1"
:cutName
set "name=%name:~0,-1%"
if not defined name exit /B
if not exist "%name%*.doc" goto cutName
for %%a in ("%name%*.doc") do (
set /A n+=1
set "name[!n!]=%%a"
echo !n!- %%a
)
exit /B
:setElem
set %1=!%2!
exit /B
this was made my Aacini on this forum.
elsewhere, I found
Code: Select all
@echo off
rem Text file with filenames
rem To be prompted for this change to 'set /p LIST=Path to text file: '
rem Or 'set LIST=%1' to run from cmd line like, filename.bat "D:\List.txt"
set LIST="D:\List.txt"
rem Path to the files to copy
rem Can be change the same as LIST
rem Or 'set FILESPATH=%2' to run like , filename.bat "D:\List.txt" "D:\Test"
set FILESPATH="D:\Test"
rem Destination path can be added here. eg set DESTPATH=C:\New Folder
rem If set change xcopy cmd to "%DESTPATH%\%DEST%\*"
rem Do not use quotes when setting DESTPATH
rem Set Destination folder based on LIST name
for %%i in (%LIST%) do set DEST=%%~ni
rem Read LIST and call :COPY_FILES for each line passing the line of text
for /F "usebackq delims==" %%i in (%LIST%) do (call :COPY_FILES "%%i")
exit
:COPY_FILES
rem Destination folder created in same location the batch file is run from
xcopy /qv %FILESPATH%\%1 .\%DEST%\*
created by 'Duzzy'
and again,
Code: Select all
@echo off
set LISTFOLDER=D:\List Files
set FILESPATH=D:\Test
set DESTPATH=D:\New Folder
for /f "tokens=*" %%i in ('dir /b ^"%LISTFOLDER%\*.txt^"') do (call :COPY_FILES "%LISTFOLDER%\%%i")
pause
exit
:COPY_FILES
for %%i in (%1) do set DEST=%%~ni
for /f "usebackq delims==" %%i in (%1) do xcopy /qv "%FILESPATH%\%%i" "%DESTPATH%\%DEST%\*"
also by duzzy.
I only learnt that this coding existed a few days ago. I have spent 8 hours watching tutorials trying to understand it, and am only finding basic ones, or little games.
What I need to learn is how to apply one of these scripts to MY context.
lets call my .txt file with the 20 .wavs 'breaks filenames world.txt'
the folder to search in is Z:\2011-MASTERS
The folder I would want them to go in, can be a new folder created by the script, that appears on the desktop
Hopefully my question is clear, if there is any info I have not provided that I need to please let me know! thanks in advance for any help! I would also be interested in some good tutorials which teach how I could create a script for this myself.
cheers all
Evan