Batch File: works under cmd-Windows , NOT under MS-DOS

July 27, 2014 at 01:08:32
Specs: Windows 7
I made these codes to backup files :

set p=C:\Users\
for /f %%a in ('dir C:\Users\ /b') do (
if not "%%a"=="Public", (
set fileDest=C:\Backup-%%a_%date:~7,2%.%date:~4,2%.%date:~10,4%
If Not Exist "%fileDest%" mkdir "%fileDest%"
set "fullPath=%p%%%a%"
xcopy "%fullPath%" %fileDest% /e /h /y /k
rem call blah.bat
)
)

When I test it under cmd of Windows 7 , it works great!!

When I try it under MS-DOS(VirtualBOX) it does not

It gives me these errors :

http://i.stack.imgur.com/LSa2G.png


See More: Batch File: works under cmd-Windows , NOT under MS-DOS

Report •

#1
July 27, 2014 at 02:05:45
It's been awhile since I wrote batch files and tried to run them in DOS, but my guess is it's not working because you're including special characters and switches and not following the 8.3 rule for filenames.

message edited by Jennifer SUMN


Report •

#2
July 27, 2014 at 02:35:03
CMD is not DOS; it only has a passing resemblance to the old OS. In all, I count 4 lines that are valid MS-DOS. They are:
set p=C:\Users\
If Not Exist "%fileDest%" mkdir "%fileDest%"
xcopy "%fullPath%" %fileDest% /e /h /y /k
rem call blah.bat

How To Ask Questions The Smart Way


Report •

#3
July 27, 2014 at 02:38:16
What you coded is a NT batch script containing statements unknown to plain DOS as FOR /F and substrings manipulation. So it can't be interpreted by the DOS command interpreter COMMAND.COM that only handles a subset of CMD.EXE's statements.

Report •

Related Solutions

#4
July 27, 2014 at 03:24:04
Is there a way to let these codes above work under DOS? such as copying necessary files to the boot-image ?

Report •

#5
July 27, 2014 at 04:05:47
As Razor2.3 said, "CMD is not DOS; it only has a passing resemblance to the old operating system".

Windows is a NT kernel based operating system that has little or nothing in common with its DOS ancestor. In other words there is no simple way to accomplish what you want even if not impossible (but not worth of).


Report •

#6
December 4, 2014 at 15:55:38
No real surprise that some fancy lines of code in a CMD file would not work in ancient MS-DOS ...

Only some very basic basic things would work, I recall that MS-DOS even may have problems with CMD (may need to rename it to BAT)

As Razor says, there not be too many lines that work, if it'll be 4, I would be amazed. Isn't XCOPY also something typical for post-MS-DOS ?

LOL, I think the first line works, and also the last line (the one with REM). All the rest is very doubtful I think.

Replacement commands ? You wish.


Report •

Ask Question