Merge different folders with identical name (8 initial digits)

0

I have thousands of folders like these:

12432434_afma_v01
12432434_afma_v02
12432434_afma_v03
12432435_afma_v01
12432435_afma_v02
12432435_afma_v03

I want to consolidate all their contents in two folders only (using as consolidating method the first 8 digits of the name):

12432434 (contains all content of the 3 merged folders)
12432435 (contains all content of the 3 merged folders)

Is this feasible?

Michelangelo

Posted 2016-11-22T16:34:34.333

Reputation: 1

Yes, this is not complicated to do with a simple script, but to write this kind of script you are better off on StackOverflow instead of SuperUser. – IronWilliamCash – 2016-11-22T16:43:22.413

1Also, you need to be prepared on how you will handle duplicate names for files or sub-folders. There is not any one size fits all answer to that. – bvaughn – 2016-11-22T16:51:59.240

Answers

0

try this:

batch.cmd

cd /d your_dir
@echo off
for /f "tokens=*" %%D in ('dir /b /a:d ".\????????_afma_v*"') do call :sr %%D
goto :eof
:sr
set s=%1
set d=%s:~0,8%
md "%d%"
move /Y "%s%\*" "%d%\"
rd "%s%"
goto :eof

Adam Silenko

Posted 2016-11-22T16:34:34.333

Reputation: 614

this is simple, but you can easy modify it... (now it replace existing files...) – Adam Silenko – 2016-11-22T19:05:43.827