iT邦幫忙

0

請問如何使用批次檔,在一文字檔內搜尋每筆資料後去比對指定目錄下的資料夾後刪除呢??

各位前輩們好:

 公司內有設定個人資料夾,由於是手動建立,故人離職後就要刪除,可否透過批次檔方式,在一文字檔內搜尋每筆資料後去比對指定目錄下的資料夾後刪除呢??

EX:
(1)比對的檔案(delAccount.txt)內容如下(帳號):
A002
A003
A006
(2)檔案伺服器(Server1)的 D:\ 下,有以下數個個人資料夾:
A001
A002
A003
A004
A005
A006
A007
A008
A009

當使用delAccount.txt內的每筆資料去比對檔案伺服器(Server1)之D:\下每個資料夾後,只要在delAccount.txt有的帳號,都會將D:\下相對應的資料夾與其子資料夾所有檔案都刪除??

圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

2 個回答

0
jeles51
iT邦研究生 3 級 ‧ 2017-03-01 11:00:23
  1. 登入Server1,
  2. 執行powershell (開始->執行->powershell)
  3. D:
  4. Get-Content delAccount.txt | Remove-Item -Force -Recurse
    以上建議先在實驗環境測試過再執行.
mctseng iT邦新手 5 級 ‧ 2017-03-02 12:56:59 檢舉

感謝前輩的指導,很實用!!

0
wadeeaton1
iT邦見習生 ‧ 2017-03-02 09:01:43

參考看看,另存成xxx.CMD,delAccount.txt放在同目錄內

@echo OFF
SET delAccount=delAccount.txt
SET delPath=\\Server1\D$\
FOR /F %%x in (%delAccount%) do (
echo ------------------------
echo 欲刪除帳號:%%x
echo ------------------------
PAUSE
rd /q/s %delPath%%%x
echo %delPath%%%x 已刪除...
echo ------------------------
PAUSE
)
mctseng iT邦新手 5 級 ‧ 2017-03-02 12:55:48 檢舉

感謝前輩的指導,很實用!!

我要發表回答

立即登入回答