sub csv_create_new_file {
	
	my ($filepath,$filename,$seperator) = @_ ; 
	
	use Text::CSV;
	
	return if !$filepath || !$filename ;
	
	unlink "$filepath/$filename" or die "Cannot remove $filepath/$filename: $!" if -e "$filepath/$filename" ;

	$seperator = ';' unless $seperator ; 

	our $csv = Text::CSV->new({ binary => 1, sep_char => $seperator, eol => "\n" }) or die "Cannot use CSV: " . Text::CSV->error_diag();

	open(our $fh, ">", "$filepath/$filename") or die "Cannot open $filepath/$filename: $!";
	  
} #------------------------------------------------------------------------------------------

sub csv_write_in_file {
	
	my ($row) = @_ ;
	$csv->print($fh, $row);
	
} #------------------------------------------------------------------------------------------

sub csv_close_file {
	
	my ($filepath) = @_ ; 
	close $fh or die "Cannot close $filepath: $!";
	
} #------------------------------------------------------------------------------------------

sub csv_clear_folder {

	my ($path,$name_to_look_for) = @_ ;

	return unless -d $path ;

	opendir(DIR, "$path") or die "cant open Directory $path: $!\n";

	while(defined($folder = readdir(DIR))) {
		if (length $folder > 2) {
			my ($file,$type) = split(/\./,$folder) ;
			if ((-e "$path/$file.csv" && !$name_to_look_for) || ($name_to_look_for && -e "$path/$file.csv" && $file =~ /$name_to_look_for/)) {
				unlink ("$path/$file.csv") or print "unable to unlink - $path/$file.csv : $!";
			}
		}
	}

	closedir(DIR) ;

} #------------------------------------------------------------------------------------

1;