问题
We have images of our warehouse stock within our database. We will pull a list of the file names for those images into a .txt file.
The content of the file-list.txt will be for example:
060128412948.jpg
068912475982.jpg
etc.
We have 3 images for each stock 2 of them are low resolution and 1 of it is a high resolution image.
I need the script to only copy the high resolution image for each stock from the folders/sub-folders into a mother directory.
This is what I have so far but this only copies the files listed in the file-list from the source destination folder.
@echo off
set src_folder=C:\Users\jakub.parszewski\Desktop\TT\SalesOrders\NewOrder
set dst_folder=C:\Users\jakub.parszewski\Desktop\TT\Test
set file_list=C:\Users\jakub.parszewski\Desktop\TT\File-list.txt
set maxbytesize=300000
for /f "delims=" %%A in (%file_list% do set size=%%~zA
for /f "delims=" %%f in (%file_list%) do (
if %size% GTR %maxbytesize%
xcopy "%src_folder%\%%f" "%dst_folder%\"
)
pause
回答1:
Whilst you think about potentially better ways of achieving a more robust method, here is a For
loop example using a method similar to your original intent.
@Echo Off
Set "src_folder=%UserProfile%\Desktop\TT\SalesOrders\NewOrder"
Set "dst_folder=%UserProfile%\Desktop\TT\Test"
Set "file_list=%UserProfile%\Desktop\TT\File-list.txt"
Set "maxbytesize=3000"
For /F "UseBackQ Delims=" %%A In ("%file_list%") Do For /F %%B In (
'Where/T /F "%src_folder%":"%%~nxA" 2^>Nul'
) Do If %%B Gtr %maxbytesize% Copy "%src_folder%\%%~nxA" "%dst_folder%">Nul
Pause
I used Copy
as your XCopy
example didn't use any options beyond a basic copy.
来源:https://stackoverflow.com/questions/44022952/batch-file-to-copy-files-from-folderssub-folders-using-a-file-list-only-if-file