简体   繁体   中英

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 ).

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.

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

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