Josh B
Josh B

Reputation: 324

Move files in specific subfolders to another subfolder

I have folder C:\Folder. In this folder I have thousands of subfolders. I want to target only those ending in cv. In these subfolders I have a file and another subfolder. C:\Folder\SubFoldercv\cv. I would like to move all the files in those subfolders to the second subfolder using CMD in Windows 10.

(So from C:\Folder\SubFoldercv to C:\Folder\SubFoldercv\cv).

Upvotes: 2

Views: 1318

Answers (2)

Sergio Soares
Sergio Soares

Reputation: 1

How to do?

subfolderHolder = uploads

FOR /D %%i IN ("%MoveDirSource%\*\%subfolderHolder%\*") DO ROBOCOPY /MOV /E "%%i" "%MoveDirDestination%\%%~nxi"

but the wild card is not working

Upvotes: 0

J.Baoby
J.Baoby

Reputation: 2231

Use for /D to find the directories ending with cv, and use robocopy to copy (or robocopy /mov to move) all files from a folder to another:

@echo off
FOR /D %%G IN ("C:\Folder\*cv") DO robocopy /mov "%%~G" "%%~G\cv" "*"

I'm currently not on a windows machine so I'm not able to test it but it should do the trick and move all files to the cv subfolder for all folders ending on cv.

If you want to use it on the command-line, use:

FOR /D %G IN ("*cv") DO robocopy /mov "%~G" "%~G\cv" "*"

instead.

EDIT: After the OP tested it, he has confirmed that it works.

Upvotes: 2

Related Questions