下面是LoadRunner中常用的有关文件方面的操作:
extern int errno;
Action()
{
char new_dir[50]="D:\\newfile1"; //定义目录
char new_file[50]="newfile1.txt"; //定义文件
char filename[1024],command[1024]; //定义数组
char filename[100]="D:\\newfile3\\newfile3.txt"; //定义文件目录
char DirString[50]="D:\\newfile2"; //定义目录
/* 创建一个目录 */
if(mkdir(new_dir))
{
lr_output_message("Create new directory %s failed",new_dir);
return -1;
}
else
{
lr_output_message("Create new directory %s successfully",new_dir);
}
/* 创建一个文件 */
sprintf(filename,"%s\\%s",new_dir,"newfile3.txt");
sprintf(command,"dir %s > %s /w",new_dir,filename);
system(command); //执行操作系统命令
lr_output_message("the new file name is:",filename);
/* 改变工作目录 */
if(chdir(DirString))
{
lr_output_message("Unable to change the directory %s",DirString);
}
else
lr_output_message("Change directory to %s",DirString);
/* 删除文件 */
if(remove(filename)==0)
lr_output_message("Remove the file %s success",filename);
else
lr_output_message("Unable to remove the file %s error %d",filename,errno);
/* 删除目录 */
if (rmdir(new_dir)==0)
lr_output_message("Remove the directory %s success",new_dir);
else
lr_output_message("Unable to remove the directory %s error %d",new_dir,errno);*/
return 0;
}