Giữ lại một số thư mục và xóa tất cả các thư mục còn lại

Sẽ có lúc bạn muốn xóa bớt các thư mục không cần thiết, nhưng muốn giữ lại một số thư mục quan trọng.

Xét trường hợp sau:

Bạn có một máy chủ chia sẽ thư mục để nhiều người cùng thao tác, ví dụ máy chủ hosting... bạn có những thư mục chứa một số dữ liệu quan trọng cần cho sự hoạt động của dịch vụ, những thư mục khác của từng hosting người dùng có thể được tạo ra tùy ý, một lúc nào đó bạn muốn dọn sạch tất cả và chỉ giữ lại số thư mục quan trọng trên.

Hoặc bạn là người dùng PC bình thường,

At a time that you'll want to clean a hard drive to reduce the list storage. You need to remove all the folders are not necessary, but retains some important folder. Here's my solution to make this job a fast one. I use the DOS Command Line and files contained in a DeleteSubFolder.bat, content as follows:

@echo off
REM — Delete all the folders in the folder D:\Data
REM — Except folders are listed below
D:
cd \Data
dir /ad /b > %temp%\folders.list
REM — Here is a list of folders you want to keep
findstr /x /v "EBooks" %temp%\folders.list > %temp%\folders1.list
findstr /x /v "Softwares" %temp%\folders1.list > %temp%\folders.list
findstr /x /v "Working" %temp%\folders.list > %temp%\folders1.list
findstr /x /v "DataBackup" %temp%\folders1.list > %temp%\folders.list
REM — Remove all remaining directory
For /f "delims=" %%i in (%temp%\folders.list) do rmdir /s /q "%%i"

When implemented DeleteSubFolder.bat files on here, all the folders inside the D:\Data and has a different name with EBooks, Softwares, Working, DataBackup will be deleted.
Be careful, because it removed immediately without asking anything more.

Mr.Phan

KTS, KSXD, Developer

You may also like...

Trả lời

Email của bạn sẽ không được hiển thị công khai. Các trường bắt buộc được đánh dấu *