1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

Solved: DOS batch file

Discussion in 'DOS/Other' started by kodemonkee, Jan 27, 2010.

Thread Status:
Not open for further replies.
Advertisement
  1. kodemonkee

    kodemonkee Thread Starter

    Joined:
    Jan 27, 2010
    Messages:
    3
    Hi,

    I am using robocopy in a batch file that when I drop a folder onto it, the batch file copies it to a location. It works fine, however, I want to copy it to the destination with the same folder name as the dropped folder. For example, if I drop the MYDOCS folder I want it to create MYDOCS folder under the backup folder. This is what I have so far:

    SET SOURCEFOLDER=%~f1
    SET DESITINATIONFOLDER=i:\backups\%COMPUTERNAME%.%USERNAME%
    robocopy %SOURCEFOLDER% %DESITINATIONFOLDER% /e /copy: DAT /r:0 /w:0 /log:i:\backups\logs\%COMPUTERNAME%_%USERNAME%.txt

    TIA
     
  2. kodemonkee

    kodemonkee Thread Starter

    Joined:
    Jan 27, 2010
    Messages:
    3
    bah nm... I got it sorry...

    SET DESITINATIONFOLDER=i:\backups\%COMPUTERNAME%.%USERNAME%\%~sn1
     
  3. TheOutcaste

    TheOutcaste

    Joined:
    Aug 7, 2007
    Messages:
    9,028
    Welcome to TSG!

    You should use %~nx1 (%~snx1 for short name form), or any folder with a period in the name will not be duplicated.
    A folder named Jan.Reports.New for example, would be named only Jan.Reports (JANREP~1 in short form), as everything after the last period is considered an extension.

    You also need to quote the paths in case the folder name, computer name, or user name contains spaces:

    Code:
    robocopy [COLOR=Red][B]"[/B][/COLOR]%SOURCEFOLDER%[COLOR=Red][B]"[/B][/COLOR] [COLOR=Red][B]"[/B][/COLOR]%DESITINATIONFOLDER%[COLOR=Red][B]"[/B][/COLOR] /e /copy:DAT /r:0 /w:0 /log:[COLOR=Red][B]"[/B][/COLOR]i:\backups\logs\%COMPUTERNAME%_%USERNAME%.txt[COLOR=Red][B]"[/B][/COLOR]
     
  4. kodemonkee

    kodemonkee Thread Starter

    Joined:
    Jan 27, 2010
    Messages:
    3
    Good points... I have changed both in the script.

    Thanks.
     
As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 733,556 other people just like you!

Loading...
Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/897997