开发者

Is there a way to list drive letters in dired?

On windows, how could I open a dired buffer showing all drive letters.开发者_开发技巧 When you do C-x d you should always provide a directory, but I want to start at the drive letters level instead of a root directory of a particular drive.

If no standard solution exists, do you have one (an extension to dired ?) ? or links to articles on the subject ?


In dired you can only view directories, and since no directory exists which contains your drive letters, you can't see a list of them.

To do this you'd have to write an emacs-lisp extension for dired.

AFAIK there's no existing extension, however, a call to wmic can give you a listing of drive letters and volume names, which would be a good starting point.

The wmic command:

wmic logicaldisk get caption,drivetype,providername,volumename

Calling it from emacs-lisp and getting the result as a string.

(let (sh-output volumes)
  (setq sh-output (shell-command-to-string "wmic LogicalDisk get Caption,DriveType,ProviderName,VolumeName"))
)

Will give you a list of the volumes (DriveType : 3 = HDD, 4 = Network Mapping, 5 = Optical.)

However, you can't get dired to recognize a buffer with this output, so you'd need to create a major mode for browsing windows volumes, which would show this listing and bind RET to find the drive letter on the current line and do a dired at it's root.

If you just want the drive letters listed...

(let (sh-output volumes)
  (setq sh-output (shell-command-to-string "wmic LogicalDisk get Caption"))
)

Will do that.


Dired+ has what you want.

Command diredp-w32-drives opens a list/menu of the Windows drives. Use RET or mouse-2 to open Dired on one of the drives. The local drives come from option diredp-w32-local-drives, which you can customize.

If you hit ^ in Dired when visiting one of your drives (e.g. C:\), then you get to the same list/menu of all drives.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜