用perl来管理下载文件夹

当我们在下载时候,一般都有一个默认的文件夹,因为指定目录比较麻烦,而且也不方便,一般都使用了默认目录。但长久下去默认目录就比较复杂,所以得对其进行管理。

下面是我写的将音乐下载文件夹的文件转移到我的音乐文件夹的一段代码,很简单,当然稍微修改也可以管理其他文件,只要修改后缀就可以了
  1. #!/usr/bin/perl -w
  2. use strict;
  3. my $root = "C://My data//music";
  4. my $target = "C://KuGou";
  5. opendir KUGOO,$target or die "can not find kugoo $!/n";
  6. my @fileList = grep(!/^/./.?$/,readdir KUGOO);
  7. closedir KUGOO;
  8. foreach my $file (@fileList){
  9.     chdir $target or die "fail to execute,$!/n";
  10.     if ($file =~ //.(txt|mp3|wma)$/i){
  11.         my $path = $target."//".$file;
  12.         my $command = "copy /Y ".'"'.$path.'" '.'"'.$root.'"';
  13.         print $command,"/n";
  14.         `$command`;
  15.     }
  16. }
  17. foreach my $file(@fileList){
  18.     my $path = $target."//".$file;
  19.     unlink $path
  20. }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值