ATTENTION: You are viewing a page formatted for mobile devices; to view the full web page, click HERE.

DonationCoder.com Software > Finished Programs

DONE: Batch file to move 'next' xx folders from A to B

(1/1)

nkormanik:
Suppose root folder A has 1000 sub-folders.

User (me) wants to deal with just 10 folders at a time.  Not all 1000.

Would like to create a batch file that moves 10 folders (in any order, no worries about that) from the root folder A to another root folder B.

Presently the solution is to just highlight with Explorer and drag over.

Better to have a little batch file to double-click on to do the job, if possible.

Any suggestions appreciated.

Nicholas Kormanik

Shades:
Why 10?

Does that imply any type of user interaction (for selection criteria input)?

Is the other root folder (receiving folder) located on the same computer or a different one in your LAN?  Or is it located on a WAN/cloud?

In case of different computers, a recursive copy to root folder B and afterwards remove the copied folders from root folder A is preferable. Not only faster, but also safer.

If no user interaction is required or desired, why do the folders exist in root folder A and why aren't they directly created/moved to root folder B to begin with? Such a use case seems like a file handling problem with one step too many.

nkormanik:
Great questions, Shades.  Wow, what a thinker.

Assume:

c:\a

c:\b

Same computer.

Why 10?  That was just a hypothetical.  If "batch file" (or .ps1 script) user can put in any number they want.  Right?

The key is to pick off 10 folders from c:\a, and move them to c:\b.

(These folder names are hypothetical, too, of course....)

Sweet and simple.

highend01:

--- ---@SETLOCAL EnableDelayedExpansion
@ECHO OFF

SET Max=10
SET Src=R:\a
SET Dst=R:\b

IF EXIST "%Src%" (
    IF EXIST "%Dst%" (
        SET /a Count = 1
        FOR /D %%I IN ("%Src%\*") DO (
            MOVE /Y "%%I" "%Dst%" >NUL 2>NUL
            IF !Count! == %Max% GOTO :EOF
            SET /a Count += 1
        )
    )
)

nkormanik:
@highend01

Well, that's magic.  No two ways about it.

Amazing.  Works perfectly.

Thank you so much, highend01.

Wonderful code.

Navigation

[0] Message Index

Go to full version