hackerwz
hackerwz

Reputation: 11

copy files of multiple folders and rename them with cmd

i have list of folders

files in all the folder are named in the same way

I want copying them in one folder without losing the order (folder 01(file01-02...) to folder 10)

I didn't find the way to do it with cmd or another way because I want to do it without any software just with windows

Upvotes: 1

Views: 1141

Answers (1)

Endoro
Endoro

Reputation: 37569

try this:

@ECHO OFF &SETLOCAL ENABLEDELAYEDEXPANSION
SET "startfolder=c:\data"
SET "targetfolder=x:\data"
for /d /r "%startfolder%" %%a in (*) do (
    SET "fname=%%~a"
    SET "fname=!fname:%startfolder%=!"
    ECHO MD "%targetfolder%!fname!\%%~nxa" 2>nul
    for %%b in ("%%~fa\*") do ECHO COPY "%%~fb" "%targetfolder%!fname!\%%~nb-new name%%~xb"
)

Look at the output and remove the word echobefore MDand COPY if it looks good.

Upvotes: 1

Related Questions