ROBOTestFrame/add_file [ Functions ]
FUNCTION
Add a single file somewhere in base_path.
INPUTS
- base_path -- base path
- filepath -- relative path to a file.
- content -- the content to go into this file
- binary -- write the raw bytes. [optional]
SOURCE
sub add_file { my $base_path = shift; my $filepath = shift; my $content = shift; my $binary = shift; my $path = $base_path . dirname( $filepath ); $path =~ s/\.$//; # Fix for Perl 5.8.0 under Linux. if ( ! -e "$path" ) { mkpath $path or die "can't create $path"; } my $full_filepath = "$base_path/$filepath"; my $file = IO::File->new(">$full_filepath") or die "Can't open $full_filepath"; if ( $binary and ( $binary eq 'binary' ) ) { binmode( $file ); } print $file $content; $file->close(); }