Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: Create a batch file to automatically backup folder to my flash drive  (Read 29963 times)

0 Members and 1 Guest are viewing this topic.

builtforkil

    Topic Starter


    Starter

    • Experience: Beginner
    • OS: Windows 7
    Hi everyone,
    I want to create a batch file to automatically copy the following folder to my flash drive.

    Folder to copy = Thunderbird OS=Windows 7
    C:\Users\WindowsUserName\AppData\ Roaming\Thunderbird
    Copy to......
    Where ever the batch file on flash drive is... for example
    if my batch file is in G:\backup i want the folder "Thunderbird" to be copied in G:\backup folder. NOTE: the drivel letter can change according to attached devices. it can be H:\backup or J:\backup. i want the batch file to copy "Thunderbird" folder regardless of drive letter of flash drive. Just copy the folder where the batch file resides.

    I want to the same batch file to work on windows XP also (if possible). the location of the folder "Thunderbird" on windows XP is
    C:\Documents and Settings\WindowsUserName\Application Data\Thunderbird

    NOTE: WindowsUserName should be the name of user currently logged on. I want it to work in any account without worrying about user name
    I have tried to read tutorials of creating batch files but could not create my batch file. Please help

    Geek-9pm


      Mastermind
    • Geek After Dark
    • Thanked: 1026
      • Gekk9pm bnlog
    • Certifications: List
    • Computer: Specs
    • Experience: Expert
    • OS: Windows 10
    Re: Create a batch file to automatically backup folder to my flash drive
    « Reply #1 on: June 19, 2013, 07:50:42 AM »
    Is this for Windows 7? I
    http://www.informationweek.com/byte/personal-tech/desktop-operating-systems/how-to-automate-synctoy-jobs-in-windows/231001020
    SyncToy is available from Microsoft.
    http://www.microsoft.com/en-us/download/details.aspx?id=15155
    There are already many attempts to automate o this kind of thing.
    Some free.
    Others you buy for absurd prices.
    Why do it in batch?
    Because of security issues, it has to be stated by somebody with administrative permissions. Getting around that can be a chore.
    Otherwise, your would just run SyncToy as administrator. Once you have created a profile, you just plug in the flash drive and start up  SyncToy with the profile.
    Is this what you want?

    foxidrive



      Specialist
    • Thanked: 268
    • Experience: Experienced
    • OS: Windows 8
    Re: Create a batch file to automatically backup folder to my flash drive
    « Reply #2 on: June 19, 2013, 09:08:26 PM »
    I gather that you are clicking a bat file on the flash drive itself.  This will backup the folder to \tb_backup in the root of the flash drive, for the current user.

    Untested - and you may need to right click and elevate permissions. 

    Code: [Select]
    @echo off
    rd /s /q "\TB_backup" 2>nul

    if exist "C:\Users\%username%\AppData\Roaming\Thunderbird\" (
    xcopy "C:\Users\%username%\AppData\Roaming\Thunderbird\*.*" "\TB_backup\" /s/h/e/k/f/c
    )

    if exist "C:\Documents and Settings\%username%\Application Data\Thunderbird\" (
    xcopy "C:\Documents and Settings\%username%\Application Data\Thunderbird\*.*" "\TB_backup\" /s/h/e/k/f/c
    )
    pause

    builtforkil

      Topic Starter


      Starter

      • Experience: Beginner
      • OS: Windows 7
      Re: Create a batch file to automatically backup folder to my flash drive
      « Reply #3 on: June 20, 2013, 06:25:06 AM »
      Thanks to both of you. I have downloaded SyncToy and i will test the code also. I will post my feedback tomorrow after testing.
      Thanks a lot guys

      patio

      • Moderator


      • Genius
      • Maud' Dib
      • Thanked: 1769
        • Yes
      • Experience: Beginner
      • OS: Windows 7
      Re: Create a batch file to automatically backup folder to my flash drive
      « Reply #4 on: June 20, 2013, 09:38:57 AM »
      It'll only work in batch if the destination drive...the flash drive...has a fixed drive letter...
      If you are moving it from to PC to PC as stated that may change and the batch file won't run properly...
      " Anyone who goes to a psychiatrist should have his head examined. "

      foxidrive



        Specialist
      • Thanked: 268
      • Experience: Experienced
      • OS: Windows 8
      Re: Create a batch file to automatically backup folder to my flash drive
      « Reply #5 on: June 20, 2013, 08:18:59 PM »
      My effort above doesn't rely on the drive letter - it uses the drive that the batch file is located on, which is the requirement I think from reading the posts.

      builtforkil

        Topic Starter


        Starter

        • Experience: Beginner
        • OS: Windows 7
        Re: Create a batch file to automatically backup folder to my flash drive
        « Reply #6 on: June 20, 2013, 11:23:46 PM »
        Thanks everybody, especially foxidrive
        Following is the code which worked for me - perfectly so far

        set backupcmd=xcopy /s /c /d /e /h /i /r /y
        %backupcmd% "%AppData%\Thunderbird" "%CD%\Thunderbird"


        It automatically copies Thunderbird folder from AppData and creates a folder named Thunderbird in the same directory where the batch file resides. The same code works on Win7, Win8, and WinXP. It does not matter which drive letter is assigned to my flash drive where the batch file resides.

        Thanks to all of you