找到了这个线程:Exclude multiple subfolders while using Powershell's method Get-Childitem 并设法用给定的参数对其进行了测试,它似乎可以正常工作,所以我很确定我使用的语法是正确的。但是,显然,考虑到我的参数,它对我不起作用。
在这里将所有内容简化为两条相关的行:
$ExcludeDirs = @('$RECYCLE.BIN','Temporary ASP.NET Files','Temporary Internet Files','Temp','System Volume Information','RECYCLER')
gci -Path T:\ -Force -Recurse | Where {!($ExcludeDirs -match [regex]::escape($_.Fullname))}
这是输出的前几行:
PS C:\Users\Angelo Mileto> $ExcludeDirs = @('$RECYCLE.BIN','Temporary ASP.NET Files','Temporary Internet Files','Temp','System Volume Information','RECYCLER')
gci -Path T:\ -Force -Recurse | Where {!($ExcludeDirs -match [regex]::escape($_.Fullname))}
Directory: T:\
Mode LastWriteTime Length Name
---- ------------- ------ ----
d--hs 12/22/2013 4:57 PM $RECYCLE.BIN
d---- 07/15/2012 2:19 PM DropBox.Dir
d---- 12/09/2010 7:18 PM ftproot
d---- 07/27/2012 5:52 PM GNS3
d---- 08/16/2014 3:44 PM New folder
d---- 05/10/2012 7:33 AM ProgramData
d--hs 04/13/2012 7:48 PM RECYCLER
d---- 03/10/2010 6:25 PM SEP
d--hs 12/28/2012 5:42 PM System Volume Information
d---- 08/08/2012 7:33 PM Temp
d---s 03/12/2014 4:57 PM Temporary Internet Files
d---- 09/24/2013 5:24 PM VMWare_8.Dir
d---- 06/07/2008 7:06 AM WINDOWS
-a--- 08/18/2013 12:48 AM 0 Cleanup_T
-a--- 12/15/2012 8:01 AM 68 Cleanup_T.txt
-a--- 03/14/2014 7:28 PM 24761548 Data_Hash1.txt
-a--- 03/14/2014 8:12 PM 24761548 Data_Hash2.txt
-a--- 09/24/2013 5:21 PM 3923 NewFolder.reg
-a-hs 09/14/2014 2:02 AM 1717879193 pagefile.sys
6
-a--- 09/24/2013 5:17 PM 335484316 Registry_BU.reg
-a--- 08/17/2014 11:58 AM 1020 TempHash.txt
-a--- 09/13/2014 6:29 PM 57466 VM_Hash1.txt
-a--- 08/17/2014 12:49 PM 0 VM_Hash2.txt
Directory: T:\$RECYCLE.BIN
Mode LastWriteTime Length Name
---- ------------- ------ ----
d--hs 04/28/2012 7:57 AM S-1-5-18
d--hs 04/15/2012 12:01 PM S-1-5-21-2447911456-218057785-4074464323-1000
d--hs 05/07/2012 5:31 PM S-1-5-21-3003357132-2481200545-788173088-1000
d--hs 09/16/2014 7:31 PM S-1-5-21-3108701050-3840048422-4210986610-1000
d--hs 12/22/2013 4:57 PM S-1-5-21-3108701050-3840048422-4210986610-1013
d--hs 08/12/2012 7:00 AM S-1-5-21-3201584925-4004853213-4110546137-1000
d--hs 04/16/2012 8:10 PM S-1-5-21-3464201764-390295408-3614804669-1000
d--hs 12/15/2012 7:43 PM S-1-5-21-3742232801-2663128855-664334430-1000
Directory: T:\$RECYCLE.BIN\S-1-5-18
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a-hs 04/28/2012 7:57 AM 129 desktop.ini
Directory: T:\$RECYCLE.BIN\S-1-5-21-2447911456-218057785-4074464323-1000
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a-hs 04/15/2012 12:01 PM 129 desktop.ini
Directory: T:\$RECYCLE.BIN\S-1-5-21-3003357132-2481200545-788173088-1000
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a-hs 05/07/2012 5:31 PM 129 desktop.ini
Directory: T:\$RECYCLE.BIN\S-1-5-21-3108701050-3840048422-4210986610-1000
很明显,您可以看到我的 ExcludeDirs 变量中的第一项是 $RECYCLE.BIN - 是的,意识到这个函数不区分大小写,但希望尽可能精确。
所以问题是,为什么它不起作用或者我错过了使用 -match 的什么?
总体目标是最终得到一个给定驱动器/目录树上所有文件的列表,然后我可以对其采取行动,但我想省略那些一直在变化的东西(即临时目录等),同时仍然得到列表系统文件和隐藏文件。
谢谢!