批处理读文件,perl 发送邮件 ,access 导出 csv

本文介绍三种实用的脚本技巧:使用批处理读取文件内容、从Access导出查询结果为CSV文件以及通过Perl发送带有附件的电子邮件。
都是工作中遇到的问题,记下来以免以后要用到:
1 批处理读文件:
set /p MString=<filename.txt
echo %MString%

此代码只读入一行

2 将access的query 导出为csv

Function exportDetail(QueryName As String)
 Dim time As String
 Dim tmp As String
 
 time = Format(Now(), "General Date")
 tmp = Replace(Replace(time, "/", "_"), ":", "_")
 curpath = Environ("workPath")
 filenamestr = curpath & "\" & QueryName + "_" + tmp & ".csv"
 Dim str As String
str = QueryName + "_" + tmp & ".csv"
Open curpath & "\" & "filename.txt" For Output As #1
  Print #1, str

Close #1

DoCmd.TransferText TransferType:=acExportDelim, _
TableName:=QueryName, FileName:=filenamestr, HasFieldNames:=True
End Function



3 Perl发送邮件(带附件)



#! /usr/local/bin/perl -w
 
use Mail::Sender;

#command line parameters
my $to       = $ARGV[0];
my $subject  = $ARGV[1];
my $file     = $ARGV[2];


#my $today_ = `date /t 2>&1`;
#chomp ($today_);

#get the correct number of args
sub validateArgs(@) {
   $argSize = @ARGV;
   if ($argSize < 3) {
      print "You must enter 3 parameters:  \"to\" \"subject\" filename \n";
      exit 101;
   }
}

sub mail{
ref ($sender = new Mail::Sender { from => '发件人',
      smtp => 'na.relay.ibm.com', boundary => 'This-is-a-mail-boundary-435427'})
or die "Error($sender) : $Mail::Sender::Error\n";
 
$sender->OpenMultipart({to => $to,
                        subject => $subject});
$sender->Body;
$sender->SendEnc(<<'*END*');
Attachment is test!
*END*
$sender->Attach(
 {description => 'test',
  ctype => '',
  encoding => '',
  disposition => '',
  file => $file
 });
$sender->Close;
}



#MAIN
select STDERR;
$| = 1;
select STDOUT;
$| = 1;

validateArgs(@ARGV);
mail();
exit(0);
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

惹不起的程咬金

来都来了,不赏点银子么

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值