locked
Batch file to move new file to another folder RRS feed

  • Question

  • Hi all, firstly please allow me to apologize as I am very new in writing scripts. 

    Here's what I am trying to perform:

    • Search in the DB backup folder and locate the latest .bak files.
    • Move the backup files to a folder inside an external drive.

    I know it seems easy to some but not for a total beginner like myself.

    Thank You.

    • Moved by Bill_Stewart Friday, May 23, 2014 6:49 PM Abandoned; outside forum scope
    Thursday, April 24, 2014 2:16 AM

Answers

  • Search in the DB backup folder and locate the latest .bak files.

    Assuming that you mean "file" rather than "files", this batch file will work:

    @echo off
    for /F "delims=" %%a in ('dir /b /od c:\sqlserver\data\backup\*.bak') do set file=%%a
    move  /Y "%file%"  "E:\Archive Folder"

    • Proposed as answer by Frederik Long Saturday, May 3, 2014 9:49 PM
    • Marked as answer by JasonOon Monday, January 28, 2019 8:23 AM
    Thursday, April 24, 2014 6:10 AM

All replies

  • You can just do this:

    Get-ChildItem c:\sqlserver\data\backup\* -include *.bak |Move-Item -Destination x:\savedbackups


    ¯\_(ツ)_/¯

    • Proposed as answer by Frederik Long Saturday, May 3, 2014 9:49 PM
    Thursday, April 24, 2014 2:33 AM
  • Search in the DB backup folder and locate the latest .bak files.

    Assuming that you mean "file" rather than "files", this batch file will work:

    @echo off
    for /F "delims=" %%a in ('dir /b /od c:\sqlserver\data\backup\*.bak') do set file=%%a
    move  /Y "%file%"  "E:\Archive Folder"

    • Proposed as answer by Frederik Long Saturday, May 3, 2014 9:49 PM
    • Marked as answer by JasonOon Monday, January 28, 2019 8:23 AM
    Thursday, April 24, 2014 6:10 AM