Batch file to copy files from folders&sub folders using a file list only if file size greater than

此生再无相见时 提交于 2020-01-07 03:59:12

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!