
我創建了一個批次文件,該文件重定向為純文字文件。批次的作用是轉到提到的路徑,並執行 dir 命令,並將輸出定向到文字檔案。
現在,當我打開文字檔案時,我會看到整個樹,但當我最後修改時,我只想要一個資料夾。
那麼,任何人都可以建議我必須給出的命令是什麼,以便它只選擇該資料夾並將其列印到我的文字檔案中。
以下是我的批次文件的內容:
S:
cd S:\log\logit-esb\dhl\subscriptions
dir >> D:\Abhi_Work\System_Monitoring\System_monitoring.txt
當我運行下面的批次文件時,輸出會定向到我的文字檔案。
Directory of S:\log\logit-esb\dhl\subscriptions
05/01/2015 04:25 PM <DIR> .
05/01/2015 04:25 PM <DIR> ..
05/01/2015 04:25 PM <DIR> processed
0 File(s) 0 bytes
3 Dir(s) 4,682,932,224 bytes free
Volume in drive S is System
Volume Serial Number is 42A7-D3B7
我的要求是我只想在輸出檔中顯示以下行
05/01/2015 04:25 PM <DIR> processed
所以任何人都可以幫助我實現這個目標。
答案1
批次檔中的以下命令將執行您想要的操作:
dir | findstr "processed" >> D:\Abhi_Work\System_Monitoring\System_monitoring.txt
您應該首先確保System_monitoring.txt
是一個空文件,因為它將>>
附加到該文件...
管道和重定向
文字檔案可以透過管道傳輸或重定向到 FINDSTR:
來自管道的資料流 TYPE file.txt | FINDSTR“搜尋字串”
透過重定向的標準輸入 FINDSTR "searchString"
各種資料來源規格是互斥的 - FINDSTR 只能使用以下之一:檔案名稱參數、/F:檔案選項、重定向輸入或管道輸入。
答案2
這是 Windows 7 中包含的 Powershell,它將顯示路徑中最近修改的資料夾。
get-childitem -path c: | sort-object LastWriteTime -descending | select -first 1 | format-table -hidetableheaders