?? lkv.cpp
字號:
#include"stdio.h"
#include"string.h"
#include"iostream.h"
#include"windows.h"
#include"winsock.h"
#include"wsipx.h"
#include"wsnwlink.h"
#pragma comment(lib,"ws2_32")
//#define MAX_PATH 256
/*
#define FILE_ATTRIBUTE_READONLY 0x00000001
#define FILE_ATTRIBUTE_HIDDEN 0x00000002
#define FILE_ATTRIBUTE_SYSTEM 0x00000004
#define FILE_ATTRIBUTE_DIRECTORY 0x00000010
#define FILE_ATTRIBUTE_ARCHIVE 0x00000020
#define FILE_ATTRIBUTE_ENCRYPTED 0x00000040
#define FILE_ATTRIBUTE_NORMAL 0x00000080
#define FILE_ATTRIBUTE_TEMPORARY 0x00000100
#define FILE_ATTRIBUTE_SPARSE_FILE 0x00000200
#define FILE_ATTRIBUTE_REPARSE_POINT 0x00000400
#define FILE_ATTRIBUTE_COMPRESSED 0x00000800
#define FILE_ATTRIBUTE_OFFLINE 0x00001000
#define FILE_ATTRIBUTE_NOT_CONTENT_INDEXED 0x00002000
typedef struct _WIN32_FIND_DATA {
DWORD dwFileAttributes;
FILETIME ftCreationTime;
FILETIME ftLastAccessTime;
FILETIME ftLastWriteTime;
DWORD nFileSizeHigh;
DWORD nFileSizeLow;
DWORD dwReserved0;
DWORD dwReserved1;
CHAR cFileName[ MAX_PATH ];
CHAR cAlternateFileName[ 16 ];
}
*/
int dealfile(char *files)
{
printf("%s\n",files);
return 1;
}
void findAllFile(char *pFilePath)
{
WIN32_FIND_DATA FindFileData;
HANDLE hFind = INVALID_HANDLE_VALUE;
char DirSpec[MAX_PATH+1];
DWORD dwError;
strncpy (DirSpec,pFilePath,strlen(pFilePath) + 1);
SetCurrentDirectory(pFilePath);
strncat (DirSpec, "\\*",3);
hFind = FindFirstFile(DirSpec, &FindFileData);
if(hFind==INVALID_HANDLE_VALUE){printf ("Invalid file handle. Error is %u\n", GetLastError());return;}
else
{
if((FindFileData.dwFileAttributes&0x10)!=0x10)dealfile(FindFileData.cFileName);
else if(strcmp(FindFileData.cFileName,".")!=0 && strcmp(FindFileData.cFileName,"..")!=0)
{
char Dir[MAX_PATH + 1];
strcpy(Dir, pFilePath);
strncat(Dir, "\\", 2);
strcat(Dir, FindFileData.cFileName);
findAllFile(Dir);
}
while (FindNextFile(hFind,&FindFileData) != 0)
{
if((FindFileData.dwFileAttributes&0x10)!=0x10)dealfile(FindFileData.cFileName);
else if(strcmp(FindFileData.cFileName,".")!=0 && strcmp(FindFileData.cFileName,"..")!=0)
{
char Dir[MAX_PATH + 1];
strcpy(Dir,pFilePath);
strncat(Dir,"\\", 2);
strcat(Dir,FindFileData.cFileName);
findAllFile(Dir);
}
}
dwError = GetLastError();
FindClose(hFind);
if(dwError!=ERROR_NO_MORE_FILES){printf ("FindNextFile error. Error is %u\n", dwError);return;}
}
}
int disknum()
{
int num=0;
DWORD DiskInfo=GetLogicalDrives();
while(DiskInfo)
{
if(DiskInfo&1)num++;
DiskInfo>>=1;
}
printf("邏輯磁盤數(shù)量=%d\n",num);
int DSLength=GetLogicalDriveStrings(0,NULL);
char* DStr = new char[DSLength];
GetLogicalDriveStrings(DSLength,(LPTSTR)DStr);
int DType;
int si=0;
BOOL fResult;
unsigned _int64 i64FreeBytesToCaller;
unsigned _int64 i64TotalBytes;
unsigned _int64 i64FreeBytes;
for(int i=0;i<DSLength/4;++i)
{
char dir[4]={DStr[si],':','\\','\0'};
printf("%s ",dir);
DType = GetDriveType(DStr+i*4);
if(DType == DRIVE_FIXED)printf(" 硬盤 ");
else if(DType == DRIVE_CDROM)printf(" 光驅(qū) ");
else if(DType == DRIVE_REMOVABLE)printf(" 移動磁盤 ");
else if(DType == DRIVE_REMOTE)printf(" 網(wǎng)絡磁盤 ");
else if(DType == DRIVE_RAMDISK)printf(" 虛擬磁盤 ");
else if(DType == DRIVE_UNKNOWN)printf(" 未知設(shè)備 ");
fResult=GetDiskFreeSpaceEx(dir,(PULARGE_INTEGER)&i64FreeBytesToCaller,(PULARGE_INTEGER)&i64TotalBytes,(PULARGE_INTEGER)&i64FreeBytes);
if(fResult)
{
printf("totalspace=%d MB ",i64TotalBytes/1024/1024);
printf("freespace =%d MB\n",i64FreeBytesToCaller/1024/1024);
}
else printf("設(shè)備未準備好\n");
si+=4;
}
return 1;
}
int ipaddress()
{
WORD wVersionRequested = MAKEWORD(1,1);//project->setting->link->objext/library modules加入ws2_32.lib
WSADATA wsaData; //或者在頭里加上#pragma comment(lib,"ws2_32")
if (WSAStartup(wVersionRequested,&wsaData)){printf("WSAStartup failed %s\n", WSAGetLastError());return -1;}
char hostname[256];
int res = gethostname(hostname, sizeof(hostname));
if (res!=0){printf("Error: %u\n", WSAGetLastError());return -1;}
//printf("hostname=%s\n", hostname);
hostent* pHostent = gethostbyname(hostname);
if (pHostent==NULL) {printf("Error: %u\n", WSAGetLastError());return -1;}
hostent& he = *pHostent;
printf("主機名稱=%s\n別名名稱=%s\n地址類型=%d(2表示為internet)\n地址長度=%d字節(jié)\n",he.h_name, he.h_aliases, he.h_addrtype, he.h_length);
sockaddr_in sa;
for (int nAdapter=0; he.h_addr_list[nAdapter]; nAdapter++)
{
memcpy(&sa.sin_addr.s_addr,he.h_addr_list[nAdapter],he.h_length);
printf("網(wǎng)絡地址: %s\n", inet_ntoa(sa.sin_addr));
}
WSACleanup();
GetSystemMetrics
return 0;
}
int main()
{
disknum();
ipaddress();
//findAllFile("d:\\");
return 1;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -