topbanner_forum
  *

avatar image

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  • Thursday March 28, 2024, 3:37 am
  • Proudly celebrating 15+ years online.
  • Donate now to become a lifetime supporting member of the site and get a non-expiring license key for all of our programs.
  • donate

Author Topic: DONE: Batch file to move 'next' xx folders from A to B  (Read 8095 times)

nkormanik

  • Participant
  • Joined in 2010
  • *
  • Posts: 552
    • View Profile
    • Donate to Member
DONE: Batch file to move 'next' xx folders from A to B
« on: March 28, 2019, 07:06 PM »
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

  • Member
  • Joined in 2006
  • **
  • Posts: 2,922
    • View Profile
    • Donate to Member
Re: DONE: Batch file to move 'next' xx folders from A to B
« Reply #1 on: March 28, 2019, 10:07 PM »
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

  • Participant
  • Joined in 2010
  • *
  • Posts: 552
    • View Profile
    • Donate to Member
Re: DONE: Batch file to move 'next' xx folders from A to B
« Reply #2 on: March 28, 2019, 11:25 PM »
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

  • Supporting Member
  • Joined in 2011
  • **
  • Posts: 188
    • View Profile
    • Donate to Member
Re: DONE: Batch file to move 'next' xx folders from A to B
« Reply #3 on: March 29, 2019, 01:09 AM »
@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
        )
    )
)
« Last Edit: March 29, 2019, 01:07 PM by highend01 »

nkormanik

  • Participant
  • Joined in 2010
  • *
  • Posts: 552
    • View Profile
    • Donate to Member
Re: DONE: Batch file to move 'next' xx folders from A to B
« Reply #4 on: March 30, 2019, 05:31 AM »
@highend01

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

Amazing.  Works perfectly.

Thank you so much, highend01.

Wonderful code.