Generate filename with a timestamp (WinRunner, TSL)

Categories: File System OperationsSource code

How to generate filename with a timestamp

Parent page: Service Functions – System (WinRunner, TSL)

public function sys_gen_file_name(in format, out fname) {
 auto t, src, year, date, time;
 format = toupper(format);
 if ((format != "DATE") && (format != "TIME") && (format != "DATETIME"))
 return(E_GENERAL_ERROR);
 src = time_str();
 src = str_replace(src, ":", "-");
 src = str_replace(src, ",", "-");
# Delete Day
 t = substr(src, 5);
# Extract Year 
 year = substr(t, length(t)-3,4);
 t = substr(t, 1, length(t)-5);
# Extract Time
 time = substr(t, length(t)-7,8);
 t = substr(t, 1, length(t)-9);
 switch(format) {
 case "DATE":
 fname = str_replace(year & "-" & t, " ", "-");
 break;
 case "TIME": 
 fname = time;
 break;
 case "DATETIME": 
 fname = str_replace(year & "-" & t, " ", "-") & " " & time;
 break;
 default:
 fname = ""; 
 break;
 }
 return(E_OK);
}

  • Leave a Reply

    * Required
    ** Your Email is never shared

Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported
This work by the author is licensed under a Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported.