How to search files from one folder to next till found
Moderator: DosItHelp
How to search files from one folder to next till found
Hi all,
Is any way to search files from one folder to another folder till found.
Say, I have
../folder1/file1.txt
../folder1/file2.txt
../folder1/file3.txt
../folder2/file1.txt
../folder2/file2.txt
../folder2/file4.txt
../folder3/file1.txt
../folder4/file2.txt
../folder5/file5.txt
assume folder name is a variable meaning it is version related, I do not want to hard code it...
Now how I can search the above files, file1 and file2 and file4, or any requirement..
to know it is folder2, is the one I needed or looking for
Thanks
William
Is any way to search files from one folder to another folder till found.
Say, I have
../folder1/file1.txt
../folder1/file2.txt
../folder1/file3.txt
../folder2/file1.txt
../folder2/file2.txt
../folder2/file4.txt
../folder3/file1.txt
../folder4/file2.txt
../folder5/file5.txt
assume folder name is a variable meaning it is version related, I do not want to hard code it...
Now how I can search the above files, file1 and file2 and file4, or any requirement..
to know it is folder2, is the one I needed or looking for
Thanks
William
Re: How to search files from one folder to next till found
Look at the command Where /?
Re: How to search files from one folder to next till found
Thanks Hackoo so much.
I did not put the requirement clearly in the previous post.
I have a list of *.S3S file in one list.txt
What I want is to search all these *.S3S file from the list.txt
then copy to a new folder..
I tried your code:
@echo off
Title Searching for *.S3S files paths and copy them to a new location
Mode con cols=90 lines=20 & color 9E
set "Pattern=S3S"
Set "Location=C:\auto_pkg_build\Sources\Source_schemes\MOCK_UP"
Set "Destination=C:\auto_pkg_build\Sources\Source_schemes\MOCK_UP_MASTER"
set "LogSearch=%~dp0%~n0.txt"
If exist "%LogSearch%" Del "%LogSearch%"
Cls
echo(
echo --------------------------------------------------------------------------
echo Please Wait a while ....... Searching is in progress .........
echo --------------------------------------------------------------------------
Where /R %Location% "*.%Pattern%" /F >>"%LogSearch%" 2>&1
)
If "%ErrorLevel%"=="1" (
Cls
echo(
echo --------------------------------------------------------------------------
echo No file(s^) found with this Pattern
echo --------------------------------------------------------------------------
pause & exit
) else (
If Not exist "%Destination%" MD "%Destination%"
Setlocal enableDelayedExpansion
@for /f "delims=" %%a in ('Type "%LogSearch%"') do (
@echo found file %%a
If not exist "%Destination%\%%~nxa" (
@Copy %%a "%Destination%"
) else (
Set /a Count+=1
@Copy %%a "%Destination%\%%~na(!Count!)%%~xa"
)
)
)
Start "" "%LogSearch%"
If exist "%Destination%" Explorer "%Destination%"
it works but everything. Actually I only want these files (*.S3S) listed in the list.txt to be searched and copied into new folder
I did not put the requirement clearly in the previous post.
I have a list of *.S3S file in one list.txt
What I want is to search all these *.S3S file from the list.txt
then copy to a new folder..
I tried your code:
@echo off
Title Searching for *.S3S files paths and copy them to a new location
Mode con cols=90 lines=20 & color 9E
set "Pattern=S3S"
Set "Location=C:\auto_pkg_build\Sources\Source_schemes\MOCK_UP"
Set "Destination=C:\auto_pkg_build\Sources\Source_schemes\MOCK_UP_MASTER"
set "LogSearch=%~dp0%~n0.txt"
If exist "%LogSearch%" Del "%LogSearch%"
Cls
echo(
echo --------------------------------------------------------------------------
echo Please Wait a while ....... Searching is in progress .........
echo --------------------------------------------------------------------------
Where /R %Location% "*.%Pattern%" /F >>"%LogSearch%" 2>&1
)
If "%ErrorLevel%"=="1" (
Cls
echo(
echo --------------------------------------------------------------------------
echo No file(s^) found with this Pattern
echo --------------------------------------------------------------------------
pause & exit
) else (
If Not exist "%Destination%" MD "%Destination%"
Setlocal enableDelayedExpansion
@for /f "delims=" %%a in ('Type "%LogSearch%"') do (
@echo found file %%a
If not exist "%Destination%\%%~nxa" (
@Copy %%a "%Destination%"
) else (
Set /a Count+=1
@Copy %%a "%Destination%\%%~na(!Count!)%%~xa"
)
)
)
Start "" "%LogSearch%"
If exist "%Destination%" Explorer "%Destination%"
it works but everything. Actually I only want these files (*.S3S) listed in the list.txt to be searched and copied into new folder
Re: How to search files from one folder to next till found
Post the contents of this file : list.txt !
Re: How to search files from one folder to next till found
list.txt
C:\auto_pkg_build\Sources\Source_schemes\TEST\T501-01122-0100-Single-Length-Key-Scheme-Pack\T501-01122-0100\Application_Signing\Signed_Schemes\QASigned_T3\500135010100.S3S
C:\auto_pkg_build\Sources\Source_schemes\TEST\T501-01122-0100-Single-Length-Key-Scheme-Pack\T501-01122-0100\Application_Signing\Signed_Schemes\QASigned_T3\500136010100.S3S
C:\auto_pkg_build\Sources\Source_schemes\TEST\T501-01122-0100-Single-Length-Key-Scheme-Pack\T501-01122-0100\Application_Signing\Signed_Schemes\QASigned_T3\500143010102.S3S
C:\auto_pkg_build\Sources\Source_schemes\TEST\T501-02233-0100-TLV-First-Key-Scheme-Pack\T501-02233-0100\Application_Signing\Signed_Schemes\QASigned_T3\500019011200.S3S
C:\auto_pkg_build\Sources\Source_schemes\TEST\T501-08680-0103-T3_Mockup_Generic_Scheme_Pack\T501-08680-0103\Application_Signing\Signed_Schemes\MockupSigned_T3\500006011000.S3S
C:\auto_pkg_build\Sources\Source_schemes\TEST\T501-08680-0103-T3_Mockup_Generic_Scheme_Pack\T501-08680-0103\Application_Signing\Signed_Schemes\MockupSigned_T3\500007011000.S3S
C:\auto_pkg_build\Sources\Source_schemes\TEST\T501-08680-0103-T3_Mockup_Generic_Scheme_Pack\T501-08680-0103\Application_Signing\Signed_Schemes\MockupSigned_T3\500008011000.S3S
C:\auto_pkg_build\Sources\Source_schemes\TEST\T501-08680-0103-T3_Mockup_Generic_Scheme_Pack\T501-08680-0103\Application_Signing\Signed_Schemes\MockupSigned_T3\500009011000.S3S
thanks
C:\auto_pkg_build\Sources\Source_schemes\TEST\T501-01122-0100-Single-Length-Key-Scheme-Pack\T501-01122-0100\Application_Signing\Signed_Schemes\QASigned_T3\500135010100.S3S
C:\auto_pkg_build\Sources\Source_schemes\TEST\T501-01122-0100-Single-Length-Key-Scheme-Pack\T501-01122-0100\Application_Signing\Signed_Schemes\QASigned_T3\500136010100.S3S
C:\auto_pkg_build\Sources\Source_schemes\TEST\T501-01122-0100-Single-Length-Key-Scheme-Pack\T501-01122-0100\Application_Signing\Signed_Schemes\QASigned_T3\500143010102.S3S
C:\auto_pkg_build\Sources\Source_schemes\TEST\T501-02233-0100-TLV-First-Key-Scheme-Pack\T501-02233-0100\Application_Signing\Signed_Schemes\QASigned_T3\500019011200.S3S
C:\auto_pkg_build\Sources\Source_schemes\TEST\T501-08680-0103-T3_Mockup_Generic_Scheme_Pack\T501-08680-0103\Application_Signing\Signed_Schemes\MockupSigned_T3\500006011000.S3S
C:\auto_pkg_build\Sources\Source_schemes\TEST\T501-08680-0103-T3_Mockup_Generic_Scheme_Pack\T501-08680-0103\Application_Signing\Signed_Schemes\MockupSigned_T3\500007011000.S3S
C:\auto_pkg_build\Sources\Source_schemes\TEST\T501-08680-0103-T3_Mockup_Generic_Scheme_Pack\T501-08680-0103\Application_Signing\Signed_Schemes\MockupSigned_T3\500008011000.S3S
C:\auto_pkg_build\Sources\Source_schemes\TEST\T501-08680-0103-T3_Mockup_Generic_Scheme_Pack\T501-08680-0103\Application_Signing\Signed_Schemes\MockupSigned_T3\500009011000.S3S
thanks
Re: How to search files from one folder to next till found
Give a try for this batch file :
Code: Select all
@echo off
Mode con cols=100 lines=5 & color 9E
Set "Location=C:\auto_pkg_build\Sources\Source_schemes\MOCK_UP"
Set "Destination=C:\auto_pkg_build\Sources\Source_schemes\MOCK_UP_MASTER"
Title Copy files from list.txt
set "List=%~dp0list.txt"
Set "CopyLog=%~dpn0_CopyLog.txt"
If exist "%CopyLog%" Del "%CopyLog%"
If not exist "%Destination%" MD "%Destination%"
Setlocal enableDelayedExpansion
@for /f "delims=" %%a in ('Type "%List%"') do (
Call :Incremental_Copy "%%~a" "%Destination%" "%CopyLog%"
)
Start "" "%CopyLog%" & exit
::**************************************************************************
:Incremental_Copy <Source> <Destination> <CopyLog>
set "Source=%~1"
set "Destination=%~2"
set "Filename=%~n1"
Set "CopyLog=%~3"
If Not Exist "%Destination%\%~nx1" (
Cls
echo(
echo --------------------------------------------------------------------------------------------
echo Copying to "%Destination%\%~nx1" ...
echo --------------------------------------------------------------------------------------------
(
@echo Copying "%Source%" "%Destination%\%~nx1"
@Copy /DVN "%Source%" "%Destination%\%~nx1"
) >> "%CopyLog%" 2>&1
) else (
If Exist "%Destination%\%Filename%(%Count%)%~x1" Set /a Count+=1 && goto Incremental_Copy
Cls
echo(
echo --------------------------------------------------------------------------------------------
echo Copying to "%Destination%\%Filename%(%Count%)%~x1" ...
echo --------------------------------------------------------------------------------------------
(
@echo Copying "%Source%" "%Destination%\%Filename%(%Count%)%~x1"
@copy /DVN "%Source%" "%Destination%\%Filename%(%Count%)%~x1"
)>> "%CopyLog%" 2>&1
Set /a "Count=1"
)
exit /b
::**************************************************************************
Re: How to search files from one folder to next till found
Awesome!!!!! work perfectly... Thanks a lot hackoo!!
Re: How to search files from one folder to next till found
Hi Hackoo,
I think I have two tasks in all.
1. to search all the files path based on the plain files list like this
500135010100.S3S
500136010100.S3S
500143010002.S3S
500019011200.S3S
500006011000.S3S
500007011000.S3S
500008011000.S3S
500009011000.S3S
to get the list.txt with path in it, like the one above I post.
2. then copy all the files with path to one folder as your code did..
I am still struggling the first task to search the folders based op the plain files list....
Thanks
I think I have two tasks in all.
1. to search all the files path based on the plain files list like this
500135010100.S3S
500136010100.S3S
500143010002.S3S
500019011200.S3S
500006011000.S3S
500007011000.S3S
500008011000.S3S
500009011000.S3S
to get the list.txt with path in it, like the one above I post.
2. then copy all the files with path to one folder as your code did..
I am still struggling the first task to search the folders based op the plain files list....
Thanks
Re: How to search files from one folder to next till found
I tried the following code to do the search and it works but only one folder. In case it searched all the files in the unique.txt that is fine. But if it has some files not found. It should print out the missing ones then continue to search another folder...
How can I do search one folder to another till?
code:
------------------------------------------------------------------------------------------------------------------------------
FOR /F %%F IN (C:\auto_pkg_build\Sources\Source_schemes\%profile%\unique.txt) DO DIR /s/p/b %%F.* >> C:\auto_pkg_build\Sources\Source_schemes\%profile%\finds.txt
-------------------------------------------------------------------------------------------------------------------------------
Thanks
How can I do search one folder to another till?
code:
------------------------------------------------------------------------------------------------------------------------------
FOR /F %%F IN (C:\auto_pkg_build\Sources\Source_schemes\%profile%\unique.txt) DO DIR /s/p/b %%F.* >> C:\auto_pkg_build\Sources\Source_schemes\%profile%\finds.txt
-------------------------------------------------------------------------------------------------------------------------------
Thanks