如果此文件夹包含100个以上的文件,如何仅移动该文件夹中的第一个文件? [英] How to move only the first file from a folder if this folder contains more than 100 files?
本文介绍了如果此文件夹包含100个以上的文件,如何仅移动该文件夹中的第一个文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果源文件夹中包含100个以上的文件,我正在尝试构建一个脚本来移动第一个文件(按名称排序).
I'm trying to build a script that moves the first file (ordered by name) if the source folder contains more than 100 files in it.
我到了这里,但是它移动了所有文件,而不是一个.
I got here but it moves all the files instead of only one.
有人可以帮我吗?
for /f %%a in ('dir /b /a-d C:\SOURCE ^|find /c /v ""') do set "remaining=%%a"
forfiles /P C:\SOURCE /M * /C "cmd /c if @isdir==FALSE if %remaining% geq 100 move @FILE "C:\TARGET""
推荐答案
您不需要 forfiles
(顺便说一句:您明确地告诉它移动所有文件(/m *
):
you don't need forfiles
(by the way: you explicitly tell it to move all files (/m *
):
@echo off
setlocal
cd /d "C:\SOURCE"
set num=0
for /f "tokens=1,* delims=:" %%a in ('dir /b /a-d /o-n * ^|findstr /n "^"') do set /a "num=%%a" & set "file=%%b"
echo debug: %num% files. To move: %file%
if %num% gtr 100 move "%file%" "c:\target\"
这篇关于如果此文件夹包含100个以上的文件,如何仅移动该文件夹中的第一个文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文