到目前为止,我运行一个.bat文件来查找存储在我们的学生共享驱动器上的所有媒体文件,然后写入我的文档中的.txt文件,例如:
dir S:*。mp3 / s>“M:\ logs \ student \ mp3.txt”
这可能不是最好的做法,我知道在2008 R2中可能有更好的工具来做到这一点。 我现在试图find一种方法来logging例如大于100mb的文件。 这是可行的.bat文件/ cmd.exe,我最好使用PowerShell,或使用Server 2008R2中的function?
@echo off rem only files bigger than %threshold% MB are listed set threshold=100 for /r %%F in (*) do call :foo %%~zF "%%F" goto :eof :foo set size=%1 set size_mb=%size:~0,-6% if not defined size_mb set size_mb=0 if %size_mb% GTR %threshold% echo.%~2 goto :eof
子例程是可悲的必要的,因为延迟扩展不想要我如何提取兆字节(是的,的确,兆字节,不是兆字节 – 我也不喜欢它,但这是最简单的)。
请注意,如果文件大小大于两个EB字节,则此方法将失败,因为cmd无法与不符合带符号的32位整数的值进行数字比较。
代码也可以在我的SVN仓库中find。
你最好用find 。
PowerShell或VBScript是要走的路。 我已经尝试了你使用Shell脚本做的事情,最后你做了很多for()和findstr调用,从大小上剥离逗号等等。
VBScript有FileSystemObject – 做一个谷歌。
PowerShell有get-childitem:
Get-childitem -LiteralPath <basepath> -Filter *.mp3 -recurse -erroraction silentlycontinue | where-object{ $_.length -gt 100MB }
以上扫描path<basepath>和所有MP3> 100MB的subdirs。
然后你可以添加到“pipe道”中:
| foreach-object{ //dosomething }
PowerShell在线帮助非常好, 试试: get-help get-childitem -detailed例如。
快乐的脚本!
哦,不要忘记,Win2k8有“文件服务器资源pipe理器” – 一个伟大的工具。