rename 可以覆盖已经存在的文件名啊, 没有问题 就和mv一样的
2009/11/17 Troy <[email protected]> > > rename OLDNAME,NEWNAME > Changes the name of a file; an existing file NEWNAME > will be > clobbered. Returns true for success, false otherwise. > 好像是newname不能是已经存在的文件名 > > btw,既然用了File::Copy,为啥还要用rename > > NAME > File::Copy - Copy files or filehandles > > SYNOPSIS > use File::Copy; > > copy("file1","file2") or die "Copy failed: $!"; > copy("Copy.pm",\*STDOUT); > move("/dev1/fileA","/dev2/fileB"); > > use File::Copy "cp"; > > $n = FileHandle->new("/a/file","r"); > cp($n,"x"); > > > > On 11月16日, 下午3时17分, earthminator <[email protected]> wrote: > > 在Linux中编写一个程序,目的是从mol文件夹中调取文件到operation文件夹中运行,再把结果传到result文件中。因为 > > dssmol.exe只能运行input.mol的文件,所以要把它改名。比且运行结果是一个output文件,然后要把它在给名放到result文件 > > 夹中。于是我编写如下程序: > > #!/usr/bin/perl > > > > use Cwd; > > use File::Path; > > use Shell; > > use File::Copy; > > > > $home_dir = cwd; > > $mol_dir = $home_dir .'/mols'; > > $operation_dir = $home_dir .'/operation'; > > $result_dir = $home_dir.'/result'; > > chair ($mol_dir); #change to molecules directory > > @mol = glob ('*.mol'); #get all molecules files > > $mol_num = @mol; > > print "Total @mol_num molecules.\n"; > > $i=0; > > while ($i<$mol_num) { > > print "mol_num[$i]"; > > rename ("mol_num[$i] , input.mol")||die $!; > > move "input.mol , /home_dir/operation"; > > system "rm -rf $input.mol"; > > chair($operation_dir); #begin to run MODEL under this directory > > system " ./dssmol.exe"; > > move "output , /home_dir/result/"; > > system "rm -rf $input.mol"; > > system "rm -rf $output"; > > chair($result_dir); #change to result directory > > rename ("output , $i")||die $!; > > system "rm -rf $output"; > > > > i++}; > > 在运行后出现的问题是 > > Not enough arguments for rename at mol1.pl line 22, near ""mol_num > > [$i] , input.mol")" > > Not enough arguments for rename at mol1.pl line 31, near ""output , > > $i")" > > Execution of mol1.pl aborted due to compilation errors. > > > > 由于刚学perl,我不知道怎么处理这个问题。。。 > > > -- Yours Sincerely Zeng Hong --~--~---------~--~----~------------~-------~--~----~ 您收到此信息是由于您订阅了 Google 论坛“PerlChina Mongers 讨论组”论坛。 要在此论坛发帖,请发电子邮件到 [email protected] 要退订此论坛,请发邮件至 [email protected] 更多选项,请通过 http://groups.google.com/group/perlchina?hl=zh-CN 访问该论坛 -~----------~----~----~----~------~----~------~--~---
