37,741
社区成员
发帖
与我相关
我的任务
分享import fileinput
import glob
import os
''' 指定目录下的*.txt内容写入target '''
stream = fileinput.FileInput(
glob.glob(os.path.join(datapath, '*.txt'))
)
lastprocess = ''
with open(target, 'wt') as handle:
for ln in stream:
if stream.isfirstline():
if lastprocess:
handle.write('=\n')
else:
lastprocess = stream.filename()
handle.write(ln)use strict;
use warnings;
use IO::File;
@ARGV = qw( res.txt t1.txt t2.txt t3.txt );
my $rfile = new IO::File(shift, 'w');
$/ = undef;
print {$rfile} "$_=\n" while(<>); 1 #!/usr/bin/env perl
2 #
3
4 use strict;
5 use warnings;
6
7 my $target = 'all.data';
8 open my $OUT, '>', $target or die $!;
9 for my $file (@ARGV) {
10 next if $file eq $target;
11 print "$file\n";
12 open my $FD, $file or die $!;
13 for my $line (<$FD>) {
14 print $OUT $line;
15 }
16 print $OUT '=' x 80, "\n";
17 close $FD;
18 }
19 close $OUT;#!/usr/bin/env perl
#
use strict;
use warnings;
my $target = 'all.txt';
open my $OUT, '>', $target or die $!;
for my $file (<*.txt>) {
next if $file eq $target;
print "$file\n";
open my $FD, $file or die $!;
for my $line (<$FD>) {
print $OUT $line;
}
print $OUT '=' x 80, "\n";
close $FD;
}
close $OUT;
import os
import time
basepath = r'D:\Program Files\workspace\OnlyForTest\src\runEnvironment\floder'
for i in range(181):
path = os.path.join(basepath, 'file_' + str(i) + '.txt')
with open(path, 'w') as f:
f.write(time.ctime() + '\n')
f.write('filename:' + 'file_' + str(i))
destpath = r'D:\Program Files\workspace\OnlyForTest\src\runEnvironment\dest\dest.txt'
with open(destpath, 'w') as f:
filelist = os.listdir(basepath)
for filename in filelist:
path = os.path.join(basepath, filename)
with open(path, 'r') as ff:
for var in ff:
f.write(var)
f.write('\n==========================\n')