首页
社区
课程
招聘
[讨论]用那个API可以搜索出本地机上所有存在的盘符
2005-12-6 12:22 6895

[讨论]用那个API可以搜索出本地机上所有存在的盘符

HSQ 活跃值
8
2005-12-6 12:22
6895
我正写一个全盘搜索的子程序,但只能自己指定盘符,无法实现所有磁盘的搜索任务。如果能够用谋个API搜索出本地机上所有存在的盘符,进行迭代搜索,那就可以实现所有磁盘文件的搜索任务了。望个位指教!!!

[培训]内核驱动高级班,冲击BAT一流互联网大厂工作,每周日13:00-18:00直播授课

收藏
点赞7
打赏
分享
最新回复 (12)
雪    币: 217
活跃值: (99)
能力值: ( LV4,RANK:50 )
在线值:
发帖
回帖
粉丝
dwing 1 2005-12-6 13:35
2
0
使用下面的函数遍历所有的盘符:

GetDriveType
The GetDriveType function determines whether a disk drive is a removable, fixed, CD-ROM, RAM disk, or network drive.

UINT GetDriveType(
  LPCTSTR lpRootPathName   // pointer to root path
);

Parameters
lpRootPathName
Pointer to a null-terminated string that specifies the root directory of the disk to return information about. If lpRootPathName is NULL, the function uses the root of the current directory.
Return Values
The return value specifies the type of drive. It can be one of the following values:

Value Meaning
DRIVE_UNKNOWN The drive type cannot be determined.
DRIVE_NO_ROOT_DIR The root directory does not exist.
DRIVE_REMOVABLE The disk can be removed from the drive.
DRIVE_FIXED The disk cannot be removed from the drive.
DRIVE_REMOTE The drive is a remote (network) drive.
DRIVE_CDROM The drive is a CD-ROM drive.
DRIVE_RAMDISK The drive is a RAM disk.
雪    币: 381
活跃值: (130)
能力值: ( LV13,RANK:330 )
在线值:
发帖
回帖
粉丝
HSQ 8 2005-12-6 20:29
3
0
在源文件中用
“extrn GetDriveType:proc
extrn lstrcatA:proc
extrn lstrcpyA:proc
.....”
引入GetDriveType,编译后出现:
Turbo Assembler  Version 5.0r  Copyright (c) 1988, 1996 Borland International
Serial No:   Tester:

Assembling file:   SearchDisk.asm
Error messages:    None
Warning messages:  None
Passes:            2

Turbo Link  Version 1.6.71.0 Copyright (c) 1993,1996 Borland International
Error: Unresolved external 'GetDriveType' referenced from module SearchDisk.asm
SearchDisk.obj
SearchDisk.map
SearchDisk.exe
Assembly OK .
请问该如何引用这个API,用相同的方法为何就是这个不能用呢?,它同样也在KENELL32.DLL中?????
雪    币: 381
活跃值: (130)
能力值: ( LV13,RANK:330 )
在线值:
发帖
回帖
粉丝
HSQ 8 2005-12-6 21:10
4
0
原来忘了说明API类型,该为GetDriveTypeA OR GetDriveTypeW后,问题已自己解决,并感谢二楼的指点
雪    币: 221
活跃值: (100)
能力值: ( LV6,RANK:90 )
在线值:
发帖
回帖
粉丝
chaykovsky 2 2005-12-9 16:47
5
0
使用GetLogicalDrives 或GetLogicalDriveStrings 可以直接得到系统中的所有盘
雪    币: 381
活跃值: (130)
能力值: ( LV13,RANK:330 )
在线值:
发帖
回帖
粉丝
HSQ 8 2005-12-12 22:33
6
0
又学一招了,但是在有些情况下还是GetDriveType比较方便
雪    币: 217
活跃值: (99)
能力值: ( LV4,RANK:50 )
在线值:
发帖
回帖
粉丝
dwing 1 2005-12-13 16:50
7
0
最初由 HSQ 发布
又学一招了,但是在有些情况下还是GetDriveType比较方便

是的.大部分的免CD补丁程序都是从GetDriveType下手的.
雪    币: 203
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
tensai 2005-12-30 16:02
8
0
我正好写了一个这样的程序,给你源代码吧

#include <windows.h>
#include <stdio.h>
main()
{
long i,j;
UCHAR buf[100];
UCHAR *cdbuf;

j=100;
i=GetLogicalDriveStrings(j,buf);

        for (j=0;j<i;j+=4)
        {
                cdbuf=&buf[j];
                switch( GetDriveType( cdbuf) )
                {
                        case DRIVE_UNKNOWN:        printf("%s is 未知驱动器\n",cdbuf);break;
                        case DRIVE_NO_ROOT_DIR:        printf("%s is 路径无效\n",cdbuf);break;
                        case DRIVE_REMOVABLE:        printf("%s is 可移动媒体\n",cdbuf);break;
                        case DRIVE_FIXED:        printf("%s is 硬盘\n",cdbuf);break;
                        case DRIVE_REMOTE:        printf("%s is 网络驱动器\n",cdbuf);break;
                        case DRIVE_CDROM:        printf("%s is CD-ROM\n",cdbuf);break;
                        case DRIVE_RAMDISK:        printf("%s is RAM 驱动器\n",cdbuf);break;
                        default:                break;
                }
        }

}
雪    币: 200
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
tomtom 2005-12-30 19:12
9
0
又学一招了,
雪    币: 142
活跃值: (91)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
小伟 2006-1-5 11:20
10
0
最初由 tensai 发布
我正好写了一个这样的程序,给你源代码吧

#include <windows.h>
#include <stdio.h>
main()
........


这是什么代码?????????看不懂!
雪    币: 515
活跃值: (1223)
能力值: ( LV12,RANK:650 )
在线值:
发帖
回帖
粉丝
RoBa 16 2006-1-5 12:40
11
0
最初由 小伟 发布


这是什么代码?????????看不懂!


C语言,如果用VC,在里面选 控制台程序 就是
雪    币: 381
活跃值: (130)
能力值: ( LV13,RANK:330 )
在线值:
发帖
回帖
粉丝
HSQ 8 2006-1-9 16:26
12
0
最初由 tensai 发布
我正好写了一个这样的程序,给你源代码吧

#include <windows.h>
#include <stdio.h>
main()
........


     C写的意义不大,我用汇编写是另用用途的,关键是只要知道用那个API,至于运用那时比较简单的事情了
雪    币: 389
活跃值: (912)
能力值: ( LV9,RANK:770 )
在线值:
发帖
回帖
粉丝
kyc 19 2006-1-9 16:50
13
0
TCHAR buf[100];
TCHAR *cdbuf;
游客
登录 | 注册 方可回帖
返回