標籤:

perl_fsync_two_folder

perl_fsync_two_folder

perl sync two folder

# 2018-09-13, by Jidor #!perl use strict ;use feature qw(say);use List::Util qw(first sum max shuffle maxstr);#use List::MoreUtils qw(uniq);use File::Spec::Functions;use File::Basename qw(dirname basename);use Data::Dumper;use Scalar::Util qw/reftype/;use File::Copy;my $src_folder = q(E:jd gi_gpu_server);my $dst_folder = q(Y:gitgi_gpu_server); my $cmd_read_win = q(type E:jd gi_gpu_server1.win.txt);my @fn_all = `$cmd_read_win`;=pod@fn_all =qw(E:jd gi_gpu_server1E:jd gi_gpu_serverMakefileE:jd gi_gpu_serverREADME.mdE:jd gi_gpu_server est.PLE:jd gi_gpu_serverincludewt.hE:jd gi_gpu_serverincludezlog.h);=cutchomp(@fn_all);my @prev = (); my $prev_mtime = "";map{ my @files = (sort{ -M "$a" <=> -M "$b" } @fn_all)[0..3]; if (@prev > 0) { my $files_mtime = &gen_size($files[0]); if ($files_mtime != $prev_mtime) { my ($original, $new_copy) = &gen_copy_cmd($files[0], $dst_folder); say($original," ", $new_copy); copy( $original, $new_copy) or die "Copy failed: $!"; # new_copy can be a dir } } @prev = (@files); $prev_mtime = &gen_size($prev[0]); sleep(3);}(0..1e6);### sub list ###sub gen_copy_cmd($fn, $dst_folder){ my $fn = shift; my $fn_r0 = $fn; $fn =~ s/.*bgi_gpu_server/$dst_folder/; return $fn_r0, $fn; }sub gen_size($){ my $fn = shift; my $mtime = (stat($fn))[9]; return $mtime;}#################

推薦閱讀:

【年薪百萬是怎樣一種體驗】11 大編程語言薪資排行榜,再不學Python就晚了!
用Python製作迷宮GIF
從零開始學習 Go 語言的切片
scala 常用操作符,常用變換
計算機科學速成課——第一個編程語言

TAG:Perl | 編程語言 |