查看完整版本: Loadrunner的C函数中怎么没有找到遍历文件的命令

wqsqiushi 2004-12-2 13:45

Loadrunner的C函数中怎么没有找到遍历文件的命令

我需要找到目录下的文件名,但是没有发现有这个C的函数,大家帮一下忙啊。

[[i] Last edited by wqsqiushi on 2004-12-2 at 13:59 [/i]]

wqsqiushi 2004-12-2 14:54

pcl_scott兄,一定要帮助我啊。

wqsqiushi 2004-12-2 17:35

版主呢,人呢.偶哭死了,

pcl2004_27 2004-12-9 13:00

不好意思,最近特别忙,所以问题回答得不及时!
lr中没有提供文件遍历函数,但是可以扩展脚本实现你需要的函数功能
win32中提供了findfilefirst findfilenext等api函数,你可以加载api函数实现你要的功能

lr中先用lr_load_dll加载包含该api函数的dll,然后直接使用就可以了,下边是lr中提供的一个例子:
lr_load_dll("user32.dll");
MessageBoxA(NULL, "This is the message body", "message_caption", 0);


下边是封装后的函数代码例子,没有经过调试,你把他用dll封装好,然后再lr中调用就可以了!
void FindFileInDir(char* rootDir, char* strRet)

{

    char fname[MAC_FILENAMELENOPATH];

    ZeroMemory(fname, MAC_FILENAMELENOPATH);



    WIN32_FIND_DATA fd;

    ZeroMemory(&fd, sizeof(WIN32_FIND_DATA));



    HANDLE hSearch;

    char filePathName[256];

    char tmpPath[256];

    ZeroMemory(filePathName, 256);

    ZeroMemory(tmpPath, 256);



    strcpy(filePathName, rootDir);



    BOOL bSearchFinished = FALSE;



    if( filePathName[strlen(filePathName) -1] != '\\' )

    {

       strcat(filePathName, "\\");

    }



    strcat(filePathName, "*");



    hSearch = FindFirstFile(filePathName, &fd);



    //Is directory

    if( (fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)

       && strcmp(fd.cFileName, ".") && strcmp(fd.cFileName, "..") )      

    {

       strcpy(tmpPath, rootDir);

       strcat(tmpPath, fd.cFileName);

       FindFileInDir(tmpPath, strRet);

    }

   

    else   if( strcmp(fd.cFileName, ".") && strcmp(fd.cFileName, "..") )

              {

                  sprintf(fname, "%-50.50s", fd.cFileName);

                  strcat(strRet + strRet[strlen(strRet)] , fname);

              }



    while( !bSearchFinished )

    {

       if( FindNextFile(hSearch, &fd) )

       {

           if( (fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)

              && strcmp(fd.cFileName, ".") && strcmp(fd.cFileName, "..") )      

           {

              strcpy(tmpPath, rootDir);

              strcat(tmpPath, fd.cFileName);

              FindFileInDir(tmpPath, strRet);

           }

   

           else   if( strcmp(fd.cFileName, ".") && strcmp(fd.cFileName, "..") )

                     {

                         sprintf(fname, "%-50.50s", fd.cFileName);

                         strcat(strRet + strRet[strlen(strRet)] , fname);

                     }

       }

       else

       {

           if( GetLastError() == ERROR_NO_MORE_FILES )          //Normal Finished

           {

              bSearchFinished = TRUE;

           }

           else

              bSearchFinished = TRUE;     //Terminate Search

       }

    }



    FindClose(hSearch);

   

}

wqsqiushi 2004-12-16 10:53

非常感谢,这些资料不多,可以说很宝贵了,我先前实在没办法是用
dir *.*/w > 1.txt
然后又打开1.txt得到的文件名,但是效率肯定低了。

sunshine_luo 2005-5-19 11:28

多谢pcl2004_27~
我以前也碰到过这种类似的情况,有些函数loadrunner中没有,当初就没有想到通过load dll的方式来实现,而是直接在loadrunner中再编写一个实现这个函数功能的一般函数来实现,实在是劳民伤财,效率也不高啊!

Lennon 2005-6-10 19:21

好强啊!
崇拜感油然而生!!

hanshiqi2004s 2005-7-5 09:37

您好,请问哪里可以下载一些测试软件呢

hanshiqi2004s 2005-7-5 09:37

您好,请问哪里可以下载一些测试软件呢?谢谢!:d

2betrue 2005-7-25 09:24

求助

pcl2004_27
你好,能讲解一些关于VS.NET2003中LoadRunnerUser的运用吗?刚接触无从下手。

gaogao 2005-11-21 13:00

收藏,越来越佩服斑竹了,呵呵 :)

lgwmlx 2006-4-12 22:31

真是佩服啊!!!!!!!!!!

千平 2006-5-15 15:37

斑竹很牛啊!!!

lidian36 2006-8-1 11:53

最近正好用到这方面的内容,受益匪浅!!谢谢斑竹!!!

softkk 2006-10-20 14:19

很好,测试也需要编程知识

叶弯 2006-10-23 23:04

的确厉害!

smallsophia 2006-11-2 15:31

开拓了思路啊!

yunan6027 2006-11-21 18:59

不错,受益菲浅,最近正在学这些sdlkfj5 sdlkfj9

junesnow 2007-5-10 17:16

sdlkfj5 强!

zhybing 2007-9-12 14:47

佩服佩服

mystufo 2007-9-28 12:01

问题太高深了,看不懂~

TEST_HUAN 2008-1-30 10:41

不知道如何用?老大

TEST_HUAN 2008-2-1 17:19

有没有人已经封装好了。vc搞不定啊

liangjz 2008-2-25 21:55

unix 可以这么写

int testdir(char *path)
{
        struct stat buf;
        if(lstat(path,&buf)<0)
        {
                return 0;
        }
        if(S_ISDIR(buf.st_mode))
        {
                return 1; //directory
        }
        return 0;
}

int directory(char *path,int *p_filenum, char   files[][128])
{
        DIR *db;
        char filename[128];
        struct dirent *p;

        db=opendir(path);
        if(db==NULL)
                return -1;


        * p_filenum =0;

        memset(filename,0,128);

        while ((p=readdir(db)))
        {
                if((strcmp(p->d_name,".")==0)||(strcmp(p->d_name,"..")==0))
                        continue;
                else
                {
                        //sprintf(filename,"%s/%s",path,p->d_name);
                        sprintf(filename,"%s",p->d_name);
                        if(testdir(filename))
                        {
                                //directory(filename);    this function no reg
                        }
                        else
                        {
                               //if core.* and  file return  ELF 32-bit LSB core file Intel 80386, version 1 (SYSV), SVR4-style, from 'iquery'
                                if ( strstr(filename,"core.") )
                                {
                                  printf("%s\n",filename);
                                  if  ( *p_filenum < 128 )
                                  {
                                        strcpy( files[*p_filenum ], filename);
                                       *p_filenum=*p_filenum +1 ;
                                  }
                                }
                        }

                }
                memset(filename,0,128);
        }

        closedir(db);
        return 0;
}
页: [1]
查看完整版本: Loadrunner的C函数中怎么没有找到遍历文件的命令