Live Chat & Podcast at 1:00PM Eastern on Sunday!
There's no such thing as a stupid question, but they're the easiest to answer.
JoinTour
Login
Search
DOS/Other
Tag Cloud
access acer asus bios bsod computer crash desktop driver drivers error ethernet excel freeze gaming hard drive hardware hdmi internet laptop malware memory monitor motherboard network printer problem ram registry router security slow software sound toshiba trojan ubuntu 11.10 uninstall usb video virus vista wifi windows windows 7 windows 7 32 bit windows 7 64 bit windows xp wireless xbox
Search
Search for:
Tech Support Guy Forums > Operating Systems > DOS/Other >
Solved: DOS batch file

Reply  
Thread Tools
kodemonkee's Avatar
Junior Member with 3 posts.
 
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
Junior Member with 3 posts.
 
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
Distinguished Member with 9,048 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" 
__________________
Microsoft MVP - Windows Expert - Consumer
Of course I know all the answers ; I just don't always match the answers to the right questions

kodemonkee's Avatar
Junior Member with 3 posts.
 
Join Date: Jan 2010
27-Jan-2010, 03:43 PM #4
Thanks TheOutcaste
Good points... I have changed both in the script.

Thanks.
Reply

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)
 
WELCOME TO TECH SUPPORT GUY! Are you looking for the solution to your computer problem? Join our site today to ask your question -- for free! Our site is run completely by volunteers who want to help you solve your computer problems. See our Welcome Guide to get started.
Thread Tools



Facebook Facebook Twitter Twitter TechGuy.tv TechGuy.tv Mobile TSG Mobile
You Are Using:
Server ID
Advertisements do not imply our endorsement of that product or service.
All times are GMT -4. The time now is 08:55 PM.
Copyright © 1996 - 2011 TechGuy, Inc. All rights reserved.

Powered by Cermak Technologies, Inc.