vc读取tbl文件的点号与坐标

因为工作的需要用了一个下午多的时间写了个读V8 tbl文件点号与坐标的程序,修改一下也可以反过来使用,将点号,坐标写入到tbl文件中去,这里使用到了双向的链表结构,值得赞啊!!!!
这里还要说一下FindFirstFile这个函数的使用有两个参数,第一个参数是查找的路径,第二个参数是保存找到的结果。这里第一个参数必须使用.来结尾。
如存放的路径是:“D:\学习研究\V8数据研究\9680”,则要在后面加上“
.
D:\学习研究\V8数据研究\9680*.
*

typedef struct LIST///链表结构定义
{
char FileName[MAX_PATH];//保存目录名称
struct LIST *plist;
struct LIST *clist;

}LIST;
typedef struct _ST
{
char dh[10];//点号
char wd[20];//维度
char jd[20];//经度
}ST;
typedef struct _HEADER
{
CHAR title[16];
CHAR str[16];
}HEADER;
LIST lt[10];
int pathindex=0;
int k=0;
char rootpath[260]={0};
VOID FindFile(char buffer,CListBox list)
{
char tmpbuffer[260]={0};
WIN32_FIND_DATAA data;
HANDLE hHand=FindFirstFile(buffer,&data);
BOOL lret=TRUE;
while(1)
{
lret=FindNextFile(hHand,&data);
if(lret==0)
{
break;
}
if(strcmp(&data.cFileName[0],".")==0)
{
continue;
}
if(strcmp(&data.cFileName[0],"…")0)
{
continue;
}
if(data.dwFileAttributes
FILE_ATTRIBUTE_DIRECTORY)//找到的是目录
{
pathindex++;
lt[pathindex-1].clist=&lt[pathindex];
lt[pathindex].plist=&lt[pathindex-1];
strcpy(lt[pathindex].FileName,&data.cFileName[0]);
strcpy(tmpbuffer,rootpath);
for(int i=1;i<=pathindex;i++)//使用链表
{
strcat(tmpbuffer,"\");
strcat(tmpbuffer,lt[i].FileName);
}

strcat(tmpbuffer,"\
.
");
FindFile(tmpbuffer,list);
pathindex–;
}
int n=(int)strstr(data.cFileName,".TBL");
if(n>0)
{
// char tmppath[260]={0};
char tmp[40]={0};
sprintf(tmp,"%d,%s",k,data.cFileName);
k++;
ST st={0};//保存点号,维度,经度
char filename[260]={0};
list->AddString(tmp);
FILE *fp=NULL;
FILE *wp=NULL;
HEADER header={0};
// memset(&header,0,32);
strcpy(filename,rootpath);
//strcat(filename,"\");
for(int i=1;i<=pathindex;i++)//使用链表
{
strcat(filename,"\");
strcat(filename,lt[i].FileName);
}

//strcat(filename,lt[pathindex].FileName);
strcat(filename,"\");
strcat(filename,data.cFileName);
fp=fopen(filename,“rb”);
n=fread(&header,32,1,fp);
// GetCurrentDirectory(260,tmppath);
// strcat(tmppath,"\result.txt");
wp=fopen(“c:\result.txt”,“a+”);//这里指定结果文件的位置
while(n>0)
{
if(strcmp(header.title,“LATG”)==0)
{
strcpy(&st.wd[0],&header.str[0]);//维度
}
if(strcmp(&header.title[0],“LNGG”)==0)
{
strcpy(&st.jd[0],&header.str[0]);//经度
}
if(strcmp(&header.title[0],“SITE”)==0)
{
strcpy(&st.dh[0],&header.str[0]);//点号
sprintf(tmp,"%d,",k);
fwrite(&tmp,1,strlen(tmp),wp);
//fwrite(",",1,1,wp);
fwrite(&st,1,sizeof(ST),wp);//写入点号、经度维度
fwrite("\r\n",1,strlen("\r\n"),wp);
fclose(wp);
break;
}
n=fread(&header,32,1,fp);
}
}

}
}
void CFindFileDlg::OnButton1()
{
// TODO: Add your control notification handler code here
UpdateData(TRUE);

char buffer[MAX_PATH]={0};
// char szFileter[]=“All Files(.)|.”;
// CString rootpath="";
// CFileDialog fd(TRUE,NULL,NULL,0,szFileter,this);

// if(IDOKfd.DoModal())
// {
// m_rootpath=fd.GetPathName();
//
// }
if(m_rootpath
"")
{
AfxMessageBox(“路径不能为空!!”);
return;
}
strcpy(lt[0].FileName,m_rootpath);
lt[0].plist=NULL;
strcpy(buffer,m_rootpath.GetBuffer(255));
strcpy(rootpath,buffer);
strcat(buffer,"\.");
FindFile(buffer,&m_list1);
UpdateData(FALSE);
}
使用说明:在上面的editbox里面输入路径,最大支持10层路径搜索,点旁边的按钮就能在下面的listbox里面列出找到的结果,并将在c盘(自己修改代码)生成结果文件result.txt

在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/haodawei123/article/details/87888620