Windows 将除上次修改的文件外的所有文件复制到新目录

Windows 将除上次修改的文件外的所有文件复制到新目录,windows,batch-file,last-modified,Windows,Batch File,Last Modified,我需要将文件从c:\prueba1移动到c:\prueba99,但我不知道如何比较源目录(c:\prueba99)中的所有文件,以移动目录中的所有文件,但目录中最后修改的文件除外。我知道有一个wmic命令带有get InstallDate,LastModified,但我不知道ms dos语法是否可以指定一个变量并比较它,以确定读取的一个文件是最后修改的 我发现了一个例子: for /f "delims=" %%A in ('wmic datafile where "drive = 'c:' an

我需要将文件从c:\prueba1移动到c:\prueba99,但我不知道如何比较源目录(c:\prueba99)中的所有文件,以移动目录中的所有文件,但目录中最后修改的文件除外。我知道有一个wmic命令带有get InstallDate,LastModified,但我不知道ms dos语法是否可以指定一个变量并比较它,以确定读取的一个文件是最后修改的

我发现了一个例子:

for /f "delims=" %%A in ('wmic datafile where "drive = 'c:' and path='\\windows\\'"
   get LastModified^,Name /format:table^|find ":"^|sort /r') do @echo %%A
并试图修改它,但没有结果,因为它似乎只是列出了数据文件名,而不是文件本身

这是我的修改版本:

for /f "skip=1 delims=" %%A  in ('wmic datafile where "drive = 'c:' and path='\\prueba1\\'"
    get LastModified^,Name /format:table^|find ":"^| sort/r') do move (%%A) c:\prueba99

更新上次修改的文件的方法:

@echo off
set $path=c:\prueba99

for /f %%a in ('dir/b/a-d/o-d "%$path%"') do (
set $Last=%%a
goto:next)

:next
echo Last modified : [ %$Last% ]

dir
命令按创建日期降序获取文件,因此第一个是最新的
for
命令迭代此列表,跳过第一个列表,将文件移动到目标文件夹。

这应该适合您,并且允许您丢弃任意数量的最新文件(对于您的情况,我选择了1):


dir/b/tw/o-d/a-d是什么意思?@MethodistMX,仅文件名(
/b
),在日期排序时使用修改日期(
/tw
),按日期降序(
/o-d
),不包括目录(
/a-d
for /f "skip=1 delims=" %%a in ('dir /b /tw /o-d /a-d c:\prueba1\*.*'
) do move "c:\prueba1\%%a" "c:\prueba99"
@echo off
setlocal

:: change the next two statements to match what you want
set srcdir=C:\prueba1
set tgtdir=C:\prueba99
if not exist %tgtdir%\*.* md %tgtdir%
set ctr=0
for /f "tokens=*" %%a in ('dir "%srcdir%" /o-d /b') do call :maybemove "%%a"
set /a ctr-=3
echo %~n0: %ctr% files were moved from %srcdir% to %tgtdir%
endlocal
goto :eof

::--------------------

:maybemove
:: increment counter and bypass the ONE newest file
set /a ctr+=1
if %ctr% leq 1 goto :eof
:: remove the double-quotes from the front and back of the filename
set fn=%~1
:: perform the move
move /y "%srcdir%\%fn%" "%tgtdir%"
goto :eof