37,720
社区成员
发帖
与我相关
我的任务
分享
@echo off &&setlocal enabledelayedexpansion
set StartDir=G:\测试
set CommDir=G:\测试\comm
set FindFileName=test.file
call :FindNextDir,%StartDir%
exit
:FindNextDir
set FindDir=%1
set CurrentDir=%cd%
cd %FindDir%
for /f %%i in ('dir /ad /b ') do (
call :FindNextFile,%%i
call :FindNextDir,%%i
)
cd /d %CurrentDir%
break
:FindNextFile
set DirName=%1
set CurrentDir=%cd%
cd %FindDir%
set DirName=%DirName:~0,2%
for /f %%i in ('dir /a-d /b %FindFileName%') do (
move %%i %CommDir%\%DirName%_%%i
)
cd /d %CurrentDir%
break
use File::Find;
use File::Copy;
use Data::Dumper;
my $folderPath = 'C:\Users\Desktop\local_files';
opendir(DIR,$folderPath) or die "$!";
@allFile=readdir DIR;
close(DIR);
delete $allFile[0];
delete $allFile[1];
for(@allFile) {
if( (defined $_) && (-d $folderPath."\\".$_)) {
my $folder = $_;
print "->Folder: ".$folderPath."\\".$folder."\n";
opendir(DH,$folderPath."\\".$folder) or die "$1";
@allSubFile = readdir DH;
delete $allSubFile[0];
delete $allSubFile[1];
for(@allSubFile) {
if((defined $_) && (-e $folderPath."\\".$folder."\\".$file)) {
my $file = $_;
print " ->File: $file\n";
print " Old name: $file\n New name: ".$folder."_".$file."\n";
rename($file, $folder."_".$file) or die "can not rename fileName$!";
}
}
close(DH);
print "\n\n";
}
}
test.bat
@echo off
setlocal enabledelayedexpansion
set c=test.file
set x=%1
for /f %%i in ('dir /B %x%') do (
set g=%x%\%%i\%c%
set e=%%i
set l=!e:~0,2!
rename !g! !l!_!c!
copy !x!\!e!\!l!_!c! %2\!l!_!c!
)
test.bat c:\big c:\common
#-*- coding: utf-8 -*-
import os
import re
import shutil
SRC_PATH = 'D:\\test'
DES_PATH = 'D:\\common'
DIR_PATTERN = r'(\w{2})\_.*'
def dealfile():
c = re.compile(DIR_PATTERN)
basic = os.listdir(SRC_PATH)
for itm in basic:
if os.path.isfile(itm):
continue
dirname = c.findall(itm)
if not dirname:
continue
dirname = dirname[0]
filelist = os.listdir(os.path.join(SRC_PATH, itm))
for f in filelist:
if os.path.isdir(f):
continue
shutil.copyfile(os.path.join(SRC_PATH, itm, f), os.path.join(DES_PATH, dirname + '_' + f))
dealfile()
print 'finished'