In danh sách file, thư mục không cần dùng phần mềm

print list file by command

Đôi khi chúng ta cần in ra danh sách các file, thư mục chứa trong ổ đĩa hoặc thư mục nào đấy để thống kê, để chia sẻ chẳng hạn. Download phần mềm về cài thì sẽ có nhiều lựa chọn và dễ dàng hơn tuy nhiên sẽ tốn thời gian tìm phần mềm và không phải phần mềm nào cũng miễn phí cả. Cài phần mềm thì có nhiều rủi ro như virus, nặng máy…

Mình sẽ hướng dẫn các bạn in ra danh sách các file, thư mục chỉ bằng 1 câu lệnh:

Ví dụ bạn muốn in ra danh sách các file trong thư mục F:\Music

Bạn mở cmd (run gõ cmd) chạy câu lệnh sau:

Dir /s /b F:\Music\*.* >F:\list.txt

Câu lệnh trên sẽ liệt kê tất cả các file, thư mục con, các file trong thư mục con trong thư mục F:\Music rồi xuất danh sách ra file F:\list.txt. Nội dung file list.txt có dạng

F:\Music\Unknown Artist – Track 1.mp3
F:\Music\Vengaboys – Boom Boom Boom Boom.mp3
F:\Music\Wonder Girls – Nobody.flv
F:\Music\Xuan Mai – Binh minh diu em.mp3
F:\Music\YeuLaiTudau-KhacViet.mp3
F:\Music\KIM\Cam Ly – Chuyen Tinh Buon Con Gai.mp3
F:\Music\KIM\Cam Ly – Em Mai La Nguoi Tinh .mp3
F:\Music\KIM\Cam Ly – Em Se La Nguoi Ra Di.mp3
F:\Music\KIM\Cam Ly – Ke Dung Sau Tinh Yeu.mp3
F:\Music\KIM\Cam Ly – Ngay Xua Hai Dua.mp3
F:\Music\KIM\Cam Ly – Nguoi Den Sau.mp3
F:\Music\Truyendai\Phai lay nguoi nhu anh -p11.mp3
F:\Music\Truyendai\Phai lay nguoi nhu anh -p12.mp3
F:\Music\Truyendai\Phai lay nguoi nhu anh -p13.mp3
F:\Music\Truyendai\Phai lay nguoi nhu anh -p14.mp3
……

Các bạn có thể tùy biến tham số cho lệnh dir để có danh sách theo ý muốn. Tham khảo lệnh dir trong windows:

DIR [drive:][path][filename] [/A[[:]attributes]] [/B] [/C] [/D] [/L] [/N]
[/O[[:]sortorder]] [/P] [/Q] [/R] [/S] [/T[[:]timefield]] [/W] [/X] [/4]

[drive:][path][filename]
Specifies drive, directory, and/or files to list.

/A          Displays files with specified attributes.
attributes   D  Directories                R  Read-only files
H  Hidden files               A  Files ready for archiving
S  System files               I  Not content indexed files
L  Reparse Points             –  Prefix meaning not
/B          Uses bare format (no heading information or summary).
/C          Display the thousand separator in file sizes.  This is the
default.  Use /-C to disable display of separator.
/D          Same as wide but files are list sorted by column.
/L          Uses lowercase.
/N          New long list format where filenames are on the far right.
/O          List by files in sorted order.
sortorder    N  By name (alphabetic)       S  By size (smallest first)
E  By extension (alphabetic)  D  By date/time (oldest first)
G  Group directories first    –  Prefix to reverse order
/P          Pauses after each screenful of information.
/Q          Display the owner of the file.
/R          Display alternate data streams of the file.
/S          Displays files in specified directory and all subdirectories.
/T          Controls which time field displayed or used for sorting
timefield   C  Creation
A  Last Access
W  Last Written
/W          Uses wide list format.
/X          This displays the short names generated for non-8dot3 file
names.  The format is that of /N with the short name inserted
before the long name. If no short name is present, blanks are
displayed in its place.
/4          Displays four-digit years

Switches may be preset in the DIRCMD environment variable.  Override
preset switches by prefixing any switch with – (hyphen)–for example, /-W.

 

Tác giả: admin

Đơn giản là mình là người đam mê công nghệ, thích học hỏi và chia sẻ. Mình mong muốn nhận được phản hồi của các bạn khi xem bất kỳ bài viết nào trên blog của mình. Mỗi ý kiến đóng góp, mỗi sự sẻ chia và góp ý của các bạn là điều mình cần nhất để blog hoàn thiện hơn. Điều đó thật sự quan trọng đối với mình. Xin chân thành cảm ơn!

Leave a Reply