Batch file to move folders from one drive to another.

Page 1 of 2 12 LastLast

  1. Posts : 221
    Windows 10 Pro 64 bit (22H2)
       #1

    Batch file to move folders from one drive to another.


    What I am trying to do is make a batch file that will move folders that I have highlghted with a mouse, form the location where they are to a location specified in the batch file.

    This is what I have so far

    Extract2Reserve.bat

    :again
    if {%1}=={} goto :EOF
    copy %1 D:\Reserve
    shift
    goto again

    I have this in "SendTo". What I do is select the folders I want to move/copy, then Right -Click > SendTo > Extract2Reserve.bat

    It sort of works but there are two problems with it

    1. It copies the files from within the folders (not the folders themselves) and dump all those files together Reserve folder. I cannot figure out how to get it to copy them within their folders inot the Reserve folder

    2. If I replace "Copy" with "Move" it doesn't work at all... it pops "Access is Denied". I want to be able to move those folders

    Ultimately, I would like to be able to execute the batch file with a keypress so that it functions like the delete key except that it sends the folders to the Reserve folder instead of the Recycle Bin.

    Can anyone spot if I have made some obvious error on that script.
      My Computers


  2. Posts : 5,327
    Windows 11 Pro 64-bit
       #2

    Try the attached batch script, it will total copy first and then does incrementally backup.
    Batch file to move folders from one drive to another. Attached Files
      My Computer


  3. Posts : 221
    Windows 10 Pro 64 bit (22H2)
    Thread Starter
       #3

    FreeBooter said:
    Try the attached batch script, it will total copy first and then does incrementally backup.
    Thank you for this reply, but it doesn't quite do what I expected. It moves all the folders from the source folder to the target folder, but what I want to do is move only those folders I select in the source folder.

    It also makes me select the source and target folder each time... but for me, the source and target folders will always be the same, so I want to be able to 'embed" those paths on the batch file.

    I do appreciate the reply, and I see that would be a really useful batch file for shifting whole bunches of folders around
      My Computers


  4. Posts : 18,044
    Win 10 Pro 64-bit v1909 - Build 18363 Custom ISO Install
       #4

    Hello @smartcooky,

    smartcooky said:
    Thank you for this reply, but it doesn't quite do what I expected. It moves all the folders from the source folder to the target folder, but what I want to do is move only those folders I select in the source folder.

    It also makes me select the source and target folder each time... but for me, the source and target folders will always be the same, so I want to be able to 'embed" those paths on the batch file.

    I do appreciate the reply, and I see that would be a really useful batch file for shifting whole bunches of folders around.

    It does NOT Move the folders, it Copies the contents of the folders from the Source to the Target, ignoring ANY files that ALREADY exist and have NOT been updated since the LAST time it was run.

    I wrote a Batch Script that I use for Backup, where I have the folder Hardcoded into the Script, BUT, I ONLY have one folder [ Hierarchy ] that ever needs to be backed up. It basically creates a folder with today's date added to it, and then copies ALL the folders [ within the Hierarchy folder ] to be backed up into it. This way, I have MANY folders [ with different backup dates ] with files that I can go back to if needed, via the date. I then just delete older folders as and when needed. It also creates a Log EVERY time it is run.

    It sounds like you are talking about several folders that need to be backed up and would therefore need a more bespoke Script.

    The thing is, everyone has their OS setup in a way that suits them, and one size does NOT fit all, so to speak.

    As another option, there is Software available that you can set specific folders etc to be backed up, either as a Task at a specified time, or when you manually run it. Maybe this is the route that you could investigate and adopt.

    I hope this helps.
      My Computer


  5. Posts : 456
    Windows 10
       #5

    For me moving the folders works perfectly. Unless the folders you are trying to move to "Reserve" exist already in "Reserve"

    Code:
    :again
    if {%1}=={} goto :EOF
    move %1 "D:\Reserve\"
    shift
    goto again
      My Computer


  6. Posts : 221
    Windows 10 Pro 64 bit (22H2)
    Thread Starter
       #6

    ricardobohner said:
    For me moving the folders works perfectly. Unless the folders you are trying to move to "Reserve" exist already in "Reserve"

    Code:
    :again
    if {%1}=={} goto :EOF
    move %1 "D:\Reserve\"
    shift
    goto again
    This doesn't work for me

    1. If I use "copy" instead of "move" in line 3, it copies the files not in their folders eg if I highlight three folders (Folder1, Folder2 and Folder3) that have 10 files in each folder, then Right-Click > SendTo > Extract2Reserve.bat, it copies all 30 files into D:\Reserve but not within their folders. The folders don't get copied at all, just the files.

    2. If I use "move" instead of "copy" it does not work at all. The command window flashes up for a moment and disappears. I put a "pause" instruction after move %1 "D:\Reserve" so that I can see what is happening, and it says "Access is Denied"

    NOTE: keep in mind that I am trying to move folders between drives, i.e.

    E:\foldername\folder1
    E:\foldername\folder2
    E:\foldername\folder3

    all to D:\Reserve

    As to your comment regarding the folders already existing in D:\Reserve, that is extremely unlikely. Each foldername is unique.. it is created automatically from the customer's surname followed by the date/time group of the moment it was created, e.g. a typical foldername created for mister Smith at 12:15:41 on September 15, 2021 will be Smith_20210915_121541
      My Computers


  7. Posts : 456
    Windows 10
       #7

    I never noticed this before but it looks like "move" command is unable to move folders from 1 drive to another. Also getting Access denied.

    Guess you would like to use a copy + delete what is basically the same as moving....

    Code:
    @echo off
    
    :again
    IF /i "%~1"=="" goto :End
    xcopy /e /i %1 "D:\Reserve\%~nx1"
    if %errorlevel% EQU 0 RD /q /s %1
    shift
    goto :again
    
    :End
    exit
      My Computer


  8. Posts : 221
    Windows 10 Pro 64 bit (22H2)
    Thread Starter
       #8

    ricardobohner said:
    I never noticed this before but it looks like "move" command is unable to move folders from 1 drive to another. Also getting Access denied.

    Guess you would like to use a copy + delete what is basically the same as moving....

    Code:
    @echo off
    
    :again
    IF /i "%~1"=="" goto :End
    xcopy /e /i %1 "D:\Reserve\%~nx1"
    if %errorlevel% EQU 0 RD /q /s %1
    shift
    goto :again
    
    :End
    exit
    OK, that's it. That works

    Thank you very much
      My Computers


  9. Posts : 16
    Win 10, Win 11
       #9

    Hi,
    If you just want to copy, you can add D:\Reserve to the Send To folder.
    You then select whatever folders with or without sub-folders and files and Send To D:\reserve.
    The whole tree will be copied with original time stamps.
    You would have to delete in source afterwards though.

    Ciao, Han

    Edit: Look into Robocopy, it is vast.
      My Computer


  10. Posts : 221
    Windows 10 Pro 64 bit (22H2)
    Thread Starter
       #10

    han jansen said:
    Hi,
    If you just want to copy, you can add D:\Reserve to the Send To folder.
    You then select whatever folders with or without sub-folders and files and Send To D:\reserve.
    The whole tree will be copied with original time stamps.
    You would have to delete in source afterwards though.

    Ciao, Han

    Edit: Look into Robocopy, it is vast.

    Thanks
    ricardobohner's post has resolved the first part of the issue, but I cannot seem to get it to run from a keypress, either by using a shortcut hotkey, or with AHK.

    I can put the batch file in the SendTo folder, then highlight the folders I want to move, then Right-Click > SendTo > Extract2Reserve.bat and the batch file executes perfectly, moving the highlighted folders to D:\Reserve. However, making a shortcut to the batch file, and then trying to use hotkey (say ALT-F12) in the shortcut's properties doesnlt work. I highlight the folders to move, press ALT-F12 and all that happens is the CMD window flashes up briefly... the folders don't get moved.

    Same happen if I use AHK.... this is the AHK script I use for that

    !F12::
    {
    Run, Extract2Reserve.bat C:\Users\MYNAME\AppData\Roaming\Microsoft\Windows\SendTo
    }
    return

    Again, the CMD window flashes up briefly... the folders don't get moved.

    I must be missing something here.
      My Computers


 

  Related Discussions
Our Sites
Site Links
About Us
Windows 10 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 10" and related materials are trademarks of Microsoft Corp.

© Designer Media Ltd
All times are GMT -5. The time now is 11:02.
Find Us




Windows 10 Forums