Computing.Net > Forums > Disk Operating System > Batch file to Create and Open Dir

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Batch file to Create and Open Dir

Reply to Message Icon

Name: mrbuggly
Date: February 18, 2004 at 16:27:53 Pacific
OS: Windows 2003 Server
CPU/Ram: 2.96/512
Comment:

Hello,

I am trying to write a batch file that will create a new directory labeled with the current date, and immediately open this new directory to copy data to it. What I have is:

@echo on
cd C:
for /F "tokens=2-4 delims=/- " %%A in ('date/T') do md %%A%%B%%C | set var= %%A%%B%%C
cd C:\%var%\
xcopy "E:\Data\*.*" /E /Y /Q /D

The batch file creates the directory with the date, but does not change the path to this new directory, so xcopy is copying the data to the C:\ and not the new directory. Any ideas?

Thanks..



Sponsored Link
Ads by Google

Response Number 1
Name: Wengier
Date: February 18, 2004 at 16:42:26 Pacific
Reply:

Hi mrbuggly, you are asking a Windows 2003 Server batch file programming question, but this is DOS forum. So you have asked your question in a *wrong* forum. Please note that Windows 2003 Server does not include "DOS". The "Command Prompt" in Win2003 is just the WinNT/2K/XP+ system console, which is NOT DOS. Below is the *quotation* from the warning messages of this forum:

"DO NOT post questions related to NT Batch scripting on this forum. Use the Programming forum.

Use the Windows NT, 2000 or XP forum for questions regarding the Windows NT, 2000 or XP "DOS" command prompt."

For more information about the "Command Prompt" (Win32 Console) in WinNT/2K/XP+, you may read this page:

http://mywebpages.comcast.net/stewartb/cmdprompt.html

Also, DOS batch and NT batch scripts are different to each other in both syntax and appearance, though WinNT/2K/XP does understand some or much (not all!) of the synatax of DOS batches (for some backward compatiblity actually) as well as the syntax of the NT batch scripts. Your batch scripts above will NOT work in DOS at all; the significantly different NT batch scripting doesn't really belong to the DOS forum. So, it's a good idea to post your question in the Programming Forum or Windows 2003 Server Forum rather than the DOS Forum, as the rule (warning messages) of this forum says, and you will probably get a better chance to be answered there.

Below are some quotations from the following site:

http://www.batch.hpg.ig.com.br/

"(Here are) Batch scripts for Windows 9x (DOS), not NT. All scripts contained in this page were developed and tested under Windows 98 Second Edition (DOS). These scripts are likely to work on other DOS based systems, such as previous versions of DOS. However, since there are many differences between NT batch scripting and DOS batch scripting, some of these scripts might not work under NT systems (Windows NT,2K,XP). In fact, I do not recommend you to use any of this code on a NT system unless a note stating otherwise is made."

On the other hand, NT batch scripting won't work on DOS systems, since DOS can't understand NT batch scripting.

Please read the above site (http://www.batch.hpg.ig.com.br/) for more information and lots of useful examples of DOS batch files.


0

Response Number 2
Name: Homeowner
Date: March 23, 2004 at 04:15:50 Pacific
Reply:

Thanks for the code Mrbuggly.
I found it useful (I am no DOS expert). You almost had it. The var variable was not set to anything which explains the failure. I changed the code around a bit so the FOR command just created the var variable. The following should work:
@echo on
cd C:
for /F "tokens=2-4 delims=/- " %%A in ('date/T') do set var= %%A%%B%%C
md %var%
cd C:\%var%\

I hope you find this useful - Who cares what Forum it ends up in as long as the problem is solved.


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Disk Operating System Forum Home


Sponsored links

Ads by Google


Results for: Batch file to Create and Open Dir

Batch file to create/edit text file www.computing.net/answers/dos/batch-file-to-createedit-text-file/9206.html

batch file to get subset of dir? www.computing.net/answers/dos/batch-file-to-get-subset-of-dir/15350.html

Using a batch file to name a file with the system date. www.computing.net/answers/dos/using-a-batch-file-to-name-a-file-with-the-system-date/3481.html