Advertisement

There's no such thing as a stupid question, but they're the easiest to answer.
Login
Search

Advertisement

DOS/Other DOS/Other
Search Search
Search for:
Tech Support Guy > > >

Solved: DOS batch file


(!)

kodemonkee's Avatar
kodemonkee kodemonkee is offline
Junior Member with 3 posts.
THREAD STARTER
 
Join Date: Jan 2010
27-Jan-2010, 10:45 AM #1
Solved: DOS batch file
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
kodemonkee's Avatar
kodemonkee kodemonkee is offline
Junior Member with 3 posts.
THREAD STARTER
 
Join Date: Jan 2010
27-Jan-2010, 11:06 AM #2
bah nm... I got it sorry...

SET DESITINATIONFOLDER=i:\backups\%COMPUTERNAME%.%USERNAME%\%~sn1
TheOutcaste's Avatar
Computer Specs
Member with 9,028 posts.
 
Join Date: Aug 2007
Location: Oregon, USA
Experience: Intermediate
27-Jan-2010, 03:15 PM #3
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 "%SOURCEFOLDER%" "%DESITINATIONFOLDER%" /e /copy:DAT /r:0 /w:0 /log:"i:\backups\logs\%COMPUTERNAME%_%USERNAME%.txt"
kodemonkee's Avatar
kodemonkee kodemonkee is offline
Junior Member with 3 posts.
THREAD STARTER
 
Join Date: Jan 2010
27-Jan-2010, 03:43 PM #4
Thanks TheOutcaste
Good points... I have changed both in the script.

Thanks.
As Seen On

BBC, Reader's Digest, PC Magazine, Today Show, Money Magazine
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.


(clock)
THIS THREAD HAS EXPIRED.
Are you having the same problem? We have volunteers ready to answer your question, but first you'll have to join for free. Need help getting started? Check out our Welcome Guide.

Search Tech Support Guy

Find the solution to your
computer problem!




Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools


WELCOME
You Are Using: Server ID
Trusted Website Back to the Top ↑