2012-07-05 51 views
0

這聽起來像一個壞笑話,但顯然來自MS的天才arent能夠使uber複雜 - 排除gci參數的工作。通過「genious」設計,它僅適用於文件,而不是整個路徑。所以如何讓它工作。 例如如何排除路徑中包含「Windows」子字符串的所有文件? 天真
gci -exclude "*Windows*" -rec
不工作解決方法圍繞設計破解Powershell gci -exclude

編輯:Google搜索/想通了這一點:

| where {$_.DirectoryName -notmatch ".*abcdef.*" } 

如果有人知道更好的解決方案,請分享。如果不會關閉問題。

+0

我想說不要關閉問題 - 回答自己的問題。這是鼓勵。 – SirPentor 2012-07-05 17:54:39

+1

好吧,tbh我會覺得有點愚蠢,因爲它更像是隨機猜測的東西,但我想我現在需要了解它爲什麼會起作用並解釋它。 :)該死的功課。 :) – NoSenseEtAl 2012-07-05 20:44:49

+0

這是一個好主意! – SirPentor 2012-07-06 14:42:36

回答

1

解決的辦法是這樣的:

gci ./ |Where{ $_.PSPath -notmatch ".*Windows.*"} 

的猜測解決這樣的問題BTW有用的東西是要知道什麼樣的方法當前對象有,對於我用獲取會員。示例輸出:

PS C:\Users\jh> gci ./ | Get-Member 


     TypeName: System.IO.DirectoryInfo 

    Name      MemberType  Definition 
    ----      ----------  ---------- 
    Mode      CodeProperty System.String Mode{get=Mode;} 
    Create     Method   void Create(), void Create(System.Security.AccessControl.DirectorySecurity ... 
    CreateObjRef    Method   System.Runtime.Remoting.ObjRef CreateObjRef(type requestedType) 
    CreateSubdirectory  Method   System.IO.DirectoryInfo CreateSubdirectory(string path), System.IO.Director... 
    Delete     Method   void Delete(), void Delete(bool recursive) 
    EnumerateDirectories  Method   System.Collections.Generic.IEnumerable[System.IO.DirectoryInfo] EnumerateDi... 
    EnumerateFiles   Method   System.Collections.Generic.IEnumerable[System.IO.FileInfo] EnumerateFiles()... 
    EnumerateFileSystemInfos Method   System.Collections.Generic.IEnumerable[System.IO.FileSystemInfo] EnumerateF... 
    Equals     Method   bool Equals(System.Object obj) 
    GetAccessControl   Method   System.Security.AccessControl.DirectorySecurity GetAccessControl(), System.... 
    GetDirectories   Method   System.IO.DirectoryInfo[] GetDirectories(), System.IO.DirectoryInfo[] GetDi... 
    GetFiles     Method   System.IO.FileInfo[] GetFiles(string searchPattern), System.IO.FileInfo[] G... 
    GetFileSystemInfos  Method   System.IO.FileSystemInfo[] GetFileSystemInfos(string searchPattern), System... 
    GetHashCode    Method   int GetHashCode() 
    GetLifetimeService  Method   System.Object GetLifetimeService() 
    GetObjectData    Method   void GetObjectData(System.Runtime.Serialization.SerializationInfo info, Sys... 
    GetType     Method   type GetType() 
    InitializeLifetimeService Method   System.Object InitializeLifetimeService() 
    MoveTo     Method   void MoveTo(string destDirName) 
    Refresh     Method   void Refresh() 
    SetAccessControl   Method   void SetAccessControl(System.Security.AccessControl.DirectorySecurity direc... 
    ToString     Method   string ToString() 
    PSChildName    NoteProperty System.String PSChildName=Contacts 
    PSDrive     NoteProperty System.Management.Automation.PSDriveInfo PSDrive=C 
    PSIsContainer    NoteProperty System.Boolean PSIsContainer=True 
    PSParentPath    NoteProperty System.String PSParentPath=Microsoft.PowerShell.Core\FileSystem::C:\Users\jh 
    PSPath     NoteProperty System.String PSPath=Microsoft.PowerShell.Core\FileSystem::C:\Users\jh\Cont... 
    PSProvider    NoteProperty System.Management.Automation.ProviderInfo PSProvider=Microsoft.PowerShell.C... 
    Attributes    Property  System.IO.FileAttributes Attributes {get;set;} 
    CreationTime    Property  datetime CreationTime {get;set;} 
    CreationTimeUtc   Property  datetime CreationTimeUtc {get;set;} 
    Exists     Property  bool Exists {get;} 
    Extension     Property  string Extension {get;} 
    FullName     Property  string FullName {get;} 
    LastAccessTime   Property  datetime LastAccessTime {get;set;} 
    LastAccessTimeUtc   Property  datetime LastAccessTimeUtc {get;set;} 
    LastWriteTime    Property  datetime LastWriteTime {get;set;} 
    LastWriteTimeUtc   Property  datetime LastWriteTimeUtc {get;set;} 
    Name      Property  string Name {get;} 
    Parent     Property  System.IO.DirectoryInfo Parent {get;} 
    Root      Property  System.IO.DirectoryInfo Root {get;} 
    BaseName     ScriptProperty System.Object BaseName {get=$this.Name;}