代码语言
.
CSharp
.
JS
Java
Asp.Net
C
MSSQL
PHP
Css
PLSQL
Python
Shell
EBS
ASP
Perl
ObjC
VB.Net
VBS
MYSQL
GO
Delphi
AS
DB2
Domino
Rails
ActionScript
Scala
代码分类
文件
系统
字符串
数据库
网络相关
图形/GUI
多媒体
算法
游戏
Jquery
Extjs
Android
HTML5
菜单
网页交互
WinForm
控件
企业应用
安全与加密
脚本/批处理
开放平台
其它
【
C
】
浏览当前磁盘文件
作者:
qianger
/ 发布于
2013/4/16
/
641
仅仅浏览当前的磁盘,控制台程序,用tinyC编译,j下、 k上、 enter确定
?/****************************************************************** File: show.c data: 2013-04-07 21:57 *****************************************************************/ #include <stdio.h> #include "find.h" #define PATH_MAX 4096*4 #define SCREEN_MAX_X 80 #define SCREEN_MAX_Y 25 char g_Path[PATH_MAX]; //from find.c extern FIND_DIR*FindDir(char *path, u_long *Cnt); extern int Free_FindDir(FIND_DIR *lpSource); extern char *CreatPath(char *path, char *name); //from screen.c extern int SetCursorInfo(int size, int visible); extern int SetCursorPosition(int x, int y); extern WORD SetCharacterAttrib(int x, int y, WORD attrib, DWORD leng); extern int ShowLine(char *content, int line, int Cnt); extern int SetTitle(char *content); extern int MoveLine(int type, SMALL_RECT *area); //from show.c int Contrl(FIND_DIR *lpDir, u_long Cnt); int ShowScreen(FIND_DIR *list, u_long position, u_long max_position, int lines, int scr_line); FIND_DIR *Key_Enter(FIND_DIR *lpDir, u_long Position, u_long *Cnt); int main(int argc, char *argv[] ) { char *lpD; u_long Cnt; FIND_DIR *lpDir = NULL; strcpy(g_Path, argv[0]); lpD =strrchr(g_Path, '\\'); strcpy(lpD, "\\*"); lpDir = FindDir(g_Path, &Cnt); Contrl(lpDir, Cnt); getchar(); return 0; } int Contrl(FIND_DIR *lpDir, u_long Cnt) { u_char get; u_long Position = 1; int len = SCREEN_MAX_X; int line= 0; WORD attrib = BACKGROUND_GREEN; WORD end_attrib ; char title[256]; SMALL_RECT Area = {0, 0, SCREEN_MAX_X, SCREEN_MAX_Y-1}; FIND_DIR *NewlpDir = NULL; NewAgain: SetCursorInfo(0,0); ShowScreen(lpDir, 1, Cnt, SCREEN_MAX_Y, 0); end_attrib = SetCharacterAttrib(0, line, attrib, len); while ( 1 ) { get = getch(); switch (get) { case 0x6b: //up toword SetCharacterAttrib(0, line, end_attrib, len); line--; Position--; if (Position <= 0) { Position = 1; } else { if (line < 0) { MoveLine(1,&Area); ShowScreen(lpDir,Position,Cnt,1,0); } } if (line < 0) { line = 0; } SetCharacterAttrib(0, line, attrib, len); break; case 0x6a: //down toword Position++; if (Position > Cnt) { Position = Cnt; break; } SetCharacterAttrib(0, line, end_attrib, len); line++; if (line > SCREEN_MAX_Y-1) { MoveLine(-1, &Area); ShowScreen(lpDir,Position,Cnt,1,SCREEN_MAX_Y-1); line = SCREEN_MAX_Y-1; } SetCharacterAttrib(0, line, attrib, len); break; case 0x20: break; case 0xd: NewlpDir = Key_Enter(lpDir, Position, &Cnt); if (NewlpDir != NULL) //successful { Position = 1; line = 0; system("cls"); lpDir = NewlpDir; goto NewAgain; } break; case 0x1b: exit(0); default: ; } } return 0; } //______________________________________________________________________ // 意思:展示指定行数到屏幕上 // 参数: 链头,开始位置,最大的位置,显示多少个,屏幕的开始位置 int ShowScreen(FIND_DIR *list, u_long position, u_long max_position, int lines, int scr_line) { char *name=NULL; int i =0; int leng =0; if (lines <= 0) return 0; i = max_position-position; if (i < 0) return 0; if (i < lines) { lines = i+1; } if (lines+scr_line > SCREEN_MAX_Y) { lines = SCREEN_MAX_Y-scr_line; } while (position > list->count) { if (list->next == NULL) return -1; position -= list->count; list = list->next; } i = position-1; while (lines-- > 0) { if (list == NULL) return -1; if (i >= list->count) { if (list->next == NULL) return -1; list = list->next; i = 0; } name = list->P_list[i]->name; leng = strlen(name); if (leng >= SCREEN_MAX_X) { leng = SCREEN_MAX_X; } ShowLine(name,scr_line,leng); scr_line++; i++; } } /*************************************************************** */ FIND_DIR *Key_Enter(FIND_DIR *lpDir, u_long Position, u_long *Cnt) { char path[sizeof(g_Path)]; char name[FILENAME_MAX]; FIND_DIR *list = lpDir; FIND_DIR *Temp = NULL; unsigned attrib= 0; u_long Temp_Cnt=0; int i = 0; while (Position > list->count) { if (list->next == NULL) return NULL; Position -= list->count; list = list->next; } i = Position-1; attrib = list->P_list[i]->attrib; strcpy(name, list->P_list[i]->name); strcpy(path, g_Path); if ( (attrib>>4)%2 == 1 ) { if (*name==0x2e && *(name+1)==0x0) //. { } else if (*name==0x2e && *(name+1)==0x2e && *(name+2)==0x0) //.. { CreatPath(path, NULL); Temp = FindDir(path,&Temp_Cnt); if (Temp == NULL) return NULL; Free_FindDir(lpDir); *Cnt = Temp_Cnt; strcpy(g_Path, path); return Temp; } else //other folder { CreatPath(path, name); Temp = FindDir(path,&Temp_Cnt); if (Temp == NULL) return NULL; Free_FindDir(lpDir); *Cnt = Temp_Cnt; strcpy(g_Path, path); return Temp; } } return NULL; }
试试其它关键字
磁盘文件
同语言下
.
获取手机通讯录 iOS去除数字以外的所有字符
.
异步加载音乐等资源
.
交通罚单管理系统
.
freemark实现,简单的替换
.
计算斐波那契数列
.
base64解码 包括解码长度
.
图像显示
.
冒泡排序
.
输入十进制数,输出指定进制
.
链式栈
可能有用的
.
C#实现的html内容截取
.
List 切割成几份 工具类
.
SQL查询 多列合并成一行用逗号隔开
.
一行一行读取txt的内容
.
C#动态修改文件夹名称(FSO实现,不移动文件)
.
c# 移动文件或文件夹
.
c#图片添加水印
.
Java PDF转换成图片并输出给前台展示
.
网站后台修改图片尺寸代码
.
处理大图片在缩略图时的展示
qianger
贡献的其它代码
(
1
)
.
浏览当前磁盘文件
Copyright © 2004 - 2024 dezai.cn. All Rights Reserved
站长博客
粤ICP备13059550号-3