在USB中打开文件 [英] file opening in usb

查看:122
本文介绍了在USB中打开文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我需要编写一个程序在不使用安装点的情况下打开USB大容量存储设备devive(pendrive)上的文件.

我使用libusb API打开设备,但是如何在不知道挂载点的情况下打开该驱动器中的文件?
是否有任何API函数可以在其中打开文本文件?
是否可以打开这样的文件?

请提供有关此问题的任何建议.

Hi,

I need to write a program to open a file on an usb mass storage devive(pendrive) without using mount point.

I used libusb API to open the device but how to open a file in that drive without knowing the mount point?
Any API functions are there to open text file in that?
Is it possible to open files like that?

Please give any suggestions regarding this.

推荐答案

我认为无论您做什么,都无法不使用安装点"来通用编写此代码.

这就是原因. 例如,对于所有我经常使用的可移动设备,我都使用挂载点-这非常方便,并且允许我仅使用一个逻辑驱动器就可以挂载所有内容(几乎像在Unix中一样).

每当我插入这样的设备时,即插即用机制被认为是唯一的已知设备,并且如果上次将其安装到安装点时,将以完全相同的方式重新安装.除非明确卸下安装,否则它不会显示为磁盘驱动器.

您不能在应用程序代码中禁用或更改它(有充分的理由).因此,如果您需要您的应用程序在所有系统上都可以工作,则应重新制定任务:如何在已挂载的USB设备上打开文件,这本身不是问题,问题在于要查找文件的位置例如,但任何限制都是无用的:它可以是#1可移动驱动器,#2可移动驱动器,#1安装点,#2安装点等.

对于驱动器,您可以确定它是否可移动:

I think you cannot universally code this "without using mount point" no matter what you do.

Here is the why.
For example, I use mount points for all removable devices I use on regular basis -- this is very convenient and allows me working with just one logical drive where I mount everything (almost like in Unix).

Every time I plug in such device, it is recognized as unique known device be the plug-in-play mechanism and is re-mounted in exact same way if it was mounted to a mount point last time. It is not shown as a disk drive until you remove the mount explicitly.

You cannot disable or change this in the application code (for a good reason). So, if you need your application to work on all systems, you should re-formulate your task: how to open a file on USB device, mounted This is not a problem per se, the problem is criteria what location of the file to look for, but any limitations are useless: it can be removable drive #1, removable drive #2, mount point #1, mount point #2, etc.

For drives, you can identify if it is removable or not:

UINT WINAPI GetDriveType(
  __in_opt  LPCTSTR lpRootPathName
);



如果此API返回DRIVE_REMOVABLE,则它是可移动的.



您应该问自己,如何定义这个位置,没什么不多.



If this API returns DRIVE_REMOVABLE it is removable.



You should ask yourself how do you want to define this location, no more no less.


这篇关于在USB中打开文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆