仅当文件大小大于时,才使用文件列表批处理文件以从文件夹和子文件夹复制文件 [英] Batch file to copy files from folders&sub folders using a file list only if file size greater than
问题描述
我们的数据库中有仓库库存的图像. 我们将这些图像的文件名列表拉入.txt文件.
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.
file-list.txt的内容例如:
The content of the file-list.txt will be for example:
060128412948.jpg
068912475982.jpg
etc.
每张库存有3张图像,其中2张是低分辨率图像,而1张是高分辨率图像.
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
推荐答案
虽然您在考虑实现更健壮的方法的潜在更好方法,但下面是一个For
循环示例,该示例使用了与您的原始意图类似的方法.>
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
我使用Copy
是因为您的XCopy
示例没有使用基本副本以外的任何选项.
I used Copy
as your XCopy
example didn't use any options beyond a basic copy.
这篇关于仅当文件大小大于时,才使用文件列表批处理文件以从文件夹和子文件夹复制文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!