当我们在下载时候,一般都有一个默认的文件夹,因为指定目录比较麻烦,而且也不方便,一般都使用了默认目录。但长久下去默认目录就比较复杂,所以得对其进行管理。
下面是我写的将音乐下载文件夹的文件转移到我的音乐文件夹的一段代码,很简单,当然稍微修改也可以管理其他文件,只要修改后缀就可以了
下面是我写的将音乐下载文件夹的文件转移到我的音乐文件夹的一段代码,很简单,当然稍微修改也可以管理其他文件,只要修改后缀就可以了
- #!/usr/bin/perl -w
- use strict;
- my $root = "C://My data//music";
- my $target = "C://KuGou";
- opendir KUGOO,$target or die "can not find kugoo $!/n";
- my @fileList = grep(!/^/./.?$/,readdir KUGOO);
- closedir KUGOO;
- foreach my $file (@fileList){
- chdir $target or die "fail to execute,$!/n";
- if ($file =~ //.(txt|mp3|wma)$/i){
- my $path = $target."//".$file;
- my $command = "copy /Y ".'"'.$path.'" '.'"'.$root.'"';
- print $command,"/n";
- `$command`;
- }
- }
- foreach my $file(@fileList){
- my $path = $target."//".$file;
- unlink $path;
- }