简体   繁体   中英

Want to batch move all files from directories and sub directories in to a different folders

I have a Windows directory and in it I have 4000 main sub-directories, in those main sub-directories I have 4000 sub-directories in which I have around 20 files each with syntax File_CreationDate_NUMBER_name.ext .

Example:

F:\\DIR\\MAINSUB1\\SUB2\\file_date_number*.rar

F:\\DIR\\MAINSUB1\\SUB3\\file1_date_number*.img

F:\\DIR\\MAINSUB1\\SUB3\\file2_date_*.txt .... till 400 SUB directories then

F:\\DIR\\MAINSUB2\\SUB1\\file2_date_number*.txt

F:\\DIR\\MAINSUB2\\SUB2\\file2_date_number*.timg

F:\\DIR\\MAINSUB2\\SUB3\\file2_date_*.html

There are 4000 MainSub directories and in each MainSub directory there are 10000 sub Directories.

I want a batch file which copies these files from SUB1, SUB2 ... under MAINSUB directories ...

Example:

D:\\FILES\\MAINSUB1\\all the files from its SUBS into it..

D:\\FILES\\MAINSUB2\\all the files from its SUBS into it..

.... for all 4000 MAINSUB directories

I also want it to give me a prompt to add date in format DDMMYYYY and NUMBER from 0-4.

This will handle the move of files (if used from command line, replace %% with %).

for /D %%f in ("d:\files\*") do for /D %%g in ("%%~ff\*") do move "%%~fg\*" "%%~ff"

Not sure where you want the timestamp added. Adjust as needed

EDIT - to adapt to comments

@echo off

setlocal enableextensions

rem from/where to copy
set "source=f:\dir"
set "target=d:\files"

set /p "df=date of files ? :"
set /p "nf=number ? :"

rem ensure final target directory exists
if not exist "%target%" mkdir "%target%"

rem do file copy
for /D %%f in ("f:\files\*") do (
    if not exist "%target%\%%~nxf" mkdir "%target%\%%~nxf" > nul
    for /D %%g in ("%%~ff\*") do (
        copy "%%~fg\*_%df%_%nf%*" "%target%\%%~nxf"
    )
)

endlocal

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM