有没有Windows命令行可以列出2015年以来我的计算机目录中的所有文件



我需要在cmd上列出一个目录2015年以来的所有文件,并显示它的aumont大小,我如何在命令行上做到这一点?我使用的是Windows7。

谢谢

以下批处理文件将在2015年创建的目录中找到所有文件,并显示匹配文件的总大小。

test.cmd

@echo off
Setlocal EnableDelayedExpansion
set _totalsize=0
for /f "usebackq" %%a in (`dir /a:-d /b`)  do (
   set _name=%%a
   set _date=%%~ta
   set _size=%%~za
   if /i "!_date:2015=!" NEQ "!_date!" (
     echo matched file !_name! with date !_date! and size !_size!
     set /a "_totalsize=_totalsize+_size"
   ) 
)
echo total size of matched files is !_totalsize!

示例输出:

F:projects>test
matched file countlines.cmd with date 23/03/2015 22:56 and size 277
matched file test.cmd with date 24/06/2015 00:24 and size 379
total size of matched files is 656
F:projects>

您可以使用robocopy检索所需的所有信息

@echo off
    setlocal enableextensions disabledelayedexpansion
    set "tempFile=%temp%%~nx0.%random%%random%%random%.tmp"
    pushd "x:wherethefilesare" && (
        rem Retrieve information 
        >"%tempFile%" (
            robocopy . . /l /nocopy /is /njh /ndl /np /ts /nc /maxage:20150101 /bytes
        )
        rem Show the file list
        findstr /r /c:"[0-9][0-9][0-9][0-9]/[0-9][0-9]/[0-9][0-9]" "%tempFile%"
        rem Show full size
        for /f "tokens=2" %%a in ('findstr /r /i /c:"^ *bytes:" "%tempFile%"') do (
            echo(
            echo Total Size: %%a bytes
            echo(
        )
        rem Clean
        del /q "%tempFile%"
        popd
    )

或者,只需从命令行,从文件夹内部处理

robocopy . . /l /nocopy /is /njh /ndl /np /ts /nc /maxage:20150101 /bytes
forfiles /d +01/01/2015 /p c: /s /c "cmd /c echo @fname @fdate

参见

forfiles /?

查看"文档"中文件夹的大小,不包括音乐、视频或图片文件夹。

for /f "skip=2 tokens=3" %A in ('Reg query "HKCUSoftwareMicrosoftWindowsCurrentVersionExplorerUser Shell Folders" /v "Personal"') do set doc=%A
for /f "usebackq tokens=2* delims= " %i IN (`dir "%doc%" /a /s ^|findstr /i /v "/"^|findstr /l /v "Pictures Music Video"`) DO @echo %j&echo.

在"音乐"中查看文件夹的大小。

for /f "skip=2 tokens=4" %A in ('Reg query "HKCUSoftwareMicrosoftWindowsCurrentVersionExplorerUser Shell Folders" /v "My Music"') do set Doc=%A
for /f "usebackq tokens=2* delims= " %i IN (`dir "%doc%" /a /s ^|findstr /i /v "/"`) DO @echo %j&echo.

查看图片中文件夹的大小。

for /f "skip=2 tokens=4" %A in ('Reg query "HKCUSoftwareMicrosoftWindowsCurrentVersionExplorerUser Shell Folders" /v "My Pictures"') do set Doc=%A
for /f "usebackq tokens=2* delims= " %i IN (`dir "%doc%" /a /s ^|findstr /i /v "/"`) DO @echo %j&echo.

查看视频中文件夹的大小。

for /f "skip=2 tokens=4" %A in ('Reg query "HKCUSoftwareMicrosoftWindowsCurrentVersionExplorerUser Shell Folders" /v "My Video"') do set Doc=%A
for /f "usebackq tokens=2* delims= " %i IN (`dir "%doc%" /a /s ^|findstr /i /v "/"`) DO @echo %j&echo.

查看桌面上文件夹的大小。

for /f "skip=2 tokens=3" %A in ('Reg query "HKCUSoftwareMicrosoftWindowsCurrentVersionExplorerUser Shell Folders" /v "Desktop"') do set doc=%A
for /f "usebackq tokens=2* delims= " %i IN (`dir "%doc%" /a /s ^|findstr /i /v "/"`) DO @echo %j&echo.

要查看文件夹的大小,请查看Windows文件夹。

for /f "usebackq tokens=2* delims= " %i IN (`dir "%windir%" /a /s ^|findstr /i /v "/"`) DO @echo %j&echo.

要查看文件夹的大小,请选择Program Files文件夹。

for /f "usebackq tokens=2* delims= " %i IN (`dir "%ProgramFiles%" /a /s ^|findstr /i /v "/"`) DO @echo %j&echo.

相关内容

  • 没有找到相关文章

最新更新