# Batch File Help!!



## dos1977 (Oct 31, 2003)

Hi,
I am trying to write a batch file which does the following:
1. Move all the files created on weekdays to be sorted to their respective days folder Example: Files created on Tuesday should be moved to a folder named "Tuesday"(When the batch file is run on Wednesday).
2. Only that particular day's created files should be present in the main directory and the other files should be moved to their respective days(created days) folder!!!!!
Could you please help me out!!!!!
Thanks.
A


----------



## john1 (Nov 25, 2000)

How far have you got ?


----------



## dos1977 (Oct 31, 2003)

No where!!!!! With respect to dates, I can handle its only with "days" that I am facing problem...How will the DOS know if the 2nd falls on a Tuesday!!! Got any ideas to help me out??


----------



## john1 (Nov 25, 2000)

I will try to get back with something.


----------



## john1 (Nov 25, 2000)

http://quasar.as.utexas.edu/BillInfo/doomsday.html

At the bottom is a short prog in JS to give day-of-the-week
for given dates.

Have a look, see what you think,
If thats the sort of thing,
then someone will have it in DOS

John


----------



## dos1977 (Oct 31, 2003)

Yes John!!! This is what I have been looking for...Do you have this in DOS program? Please let me know and thank you!!!!


----------



## john1 (Nov 25, 2000)

Sorry this level of programming is out of my league.
However that page does offer the source code,
Maybe you could 'pick it over'
to find what you need.

If it can be done with a short JavaScript program,
then i am sure it can be done with a shorter DOS program.

Give this post a day or so to sit on this forum,
there are some very smart people coming and going here,
someone may kick in with just the DOS commands or prog
that you need.

If i see anything similar in DOS, i will come back with it.

Best of luck with it, 
John


----------



## john1 (Nov 25, 2000)

http://www.computing.net/unix/wwwboard/forum/5243.html
Maybe worth a look.

Does this have to be independent?
I mean is it on a running PC, that has a clock ?
Could it take the info from the clock program?
The weekday is in there somewhere.


----------



## dos1977 (Oct 31, 2003)

I definitely hope(Pray) that someone would do this in DOS and help me out..Since I am a novice in computers!!!!Thanks again, John.


----------



## john1 (Nov 25, 2000)

Hi,

I'm not sure i understand what this says.
But i think it says you can get the day of the week
from the system clock.
Day of week : 0=Sun, 1=Mon...6=Sat

http://www.rtx.com/ttips4.htm

Have a look, see what you think.
John


----------



## john1 (Nov 25, 2000)

_
An old technique is to grab the DOS date/time and set it to the file's
date or whatever date you're looking for, then read the the day of the
week from DOS. Finally, put back the saved date and time. I don't know
what algorithm is used by DOS, but at least it'll match whatever DOS
would return about the date._

Taken from:
http://dbforums.com/arch/132/2003/9/889064

This sort of matches what i was thinking,
about the system clock.


----------



## dos1977 (Oct 31, 2003)

the trx website's code does not work!!!! But, I m trying to write the Javascript program to DOS using the online JAVA to DOS conversion codes help.......Thanks again!!!!!


----------



## john1 (Nov 25, 2000)

try that site in 'Run' instead ...


----------



## coderitr (Oct 12, 2003)

I can write a program in c or visual basic to do what you want (I think) but I need some more information. What operating system is the target machine. Is it truly DOS (16 bit) or do you want to run the program in the command prompt of a Windows operating system. Please post complete requirements.


----------



## john1 (Nov 25, 2000)

Hi Dos1977,

Heres an extract from that site you couldn't get to,










It looks like "coderitr" may be able to help you more with this,
let him know various details like if getting the day from the
system clock will do, or if it has to figure it from the date
given.
If the program has to be portable, like on a disk, to go from
machine to machine, or if it is always on the same machine.

Best of luck with it, John


----------



## codejockey (Feb 11, 2002)

Well, I'm not sure if this is what you're after or not, but it was an interesting question, nonetheless ... it turns out that despite the lack of real batch programming commands in MS-DOS, it's possible to get the day of the week from the current date, using nothing more than DOS batch file commands. The solution is a bit messy, as it relies on temporary files that need to be deleted, but it's portable to any version of DOS as well as NT, etc. The script actually determines the current date, time and day of week and puts them in environment variables for use by other programs:

```
REM determine current date, time and day of week from system clock
@echo off
if not "%3"=="" goto setenv
echo %0 @prompt $d $t > dow.bat
echo command /c dow.bat > rundow.bat
rundow

:setenv
if exist dow.bat del dow.bat 
if exist rundow.bat del rundow.bat
set DOW=%1
set SYSDATE=%2
set SYSTIME=%3
```
After running the script, you can type set at the command line to see the values of DOW, SYSDATE and SYSTIME in your environment; other batch programs can use these variables simply by referencing them (e.g., %DOW% will be converted to the day of the week -- try echo %DOW% at the command line, for example).

Hope this helps -- and good luck with your project!


----------



## john1 (Nov 25, 2000)

Hmm ..

i couldn't get that to work ...


----------



## codejockey (Feb 11, 2002)

Gack! -- what sort of errors were you getting? I ran the script in a pure DOS environment (6.22, I think).


----------



## codejockey (Feb 11, 2002)

Multiple gack! -- never mind, I see I got a bit enthusiastic with the echo command when I typed in the code ... 

```
REM determine current date, time and day of week from system clock
@echo off
if not "%3"=="" goto setenv
echo %0 @prompt $d $t > dow.bat
command /c dow.bat > rundow.bat           <---- this is the corrected line
rundow

:setenv
if exist dow.bat del dow.bat 
if exist rundow.bat del rundow.bat
set DOW=%1
set SYSDATE=%2
set SYSTIME=%3
```
Sorry for any confusion/lost time.


----------



## dos1977 (Oct 31, 2003)

AAAhhh!!!! Nothing's workin!!!! Sorry for the frustration...I think I will go MAD!!! Lol!!!


----------



## codejockey (Feb 11, 2002)

Are you saying that this (revised) code still doesn't work for you? You put it into a .bat file (maybe called something like getdow.bat or similar) and execute it -- and you don't get new values in your environment? What results do you get? If you comment out the lines that delete dow.bat and rundow.bat, you can look at/post those files, which may offer a clue.

Additional info appreciated.


----------



## dos1977 (Oct 31, 2003)

Hi Code,
I ran the DOW.bat and when I type either echo %DOW% or %DOW% as suggested by you, I get the "DOW"(with echo) and DOW is not an internal command(with %DOW%)...When I view the rundow.bat I see set $d $t in the batch file and nothin else! Please let me know where I am going wrong...
Thanks


----------



## dos1977 (Oct 31, 2003)

Know what, I think I found the code online......
@ECHO OFF
REM WHICHDAY.BAT

WDAY
IF ERRORLEVEL 7 GOTO SAT
IF ERRORLEVEL 6 GOTO FRI
IF ERRORLEVEL 5 GOTO THU
IF ERRORLEVEL 4 GOTO WED
IF ERRORLEVEL 3 GOTO TUE
IF ERRORLEVEL 2 GOTO MON
IF ERRORLEVEL 1 GOTO SUN

:SUN
ECHO Sunday
PAUSE
GOTO DONE

:MON
Echo Monday
PAUSE
GOTO DONE

:TUE
ECHO Tuesday
PAUSE
GOTO DONE

:WED
ECHO Wednesday
PAUSE
GOTO DONE

:THU
ECHO Thursday
PAUSE
GOTO DONE

:FRI
ECHO Friday
PAUSE
GOTO DONE

:SAT
ECHO Saturday
PAUSE
GOTO DONE

ONE
ECHO DONE
and make sure the attached wday.com is in the directory as the batch file and run it!!!!
Thanks a lot for the help, Gentlemen!
PS: Sorry could not attach the .com file! If need be please shoot me an email and I will send the .com file.


----------



## codejockey (Feb 11, 2002)

OK, let me try to explain things a bit better this time ...

You need to take the code I posted and put it in a file. You can name the file anything you like, as long as it ends in .bat. So, for example, you could put all of the code in a file named dodow.bat or setdow.bat or fred.bat -- it really doesn't matter as long as the file ends with a .bat extension. That is the script you will execute. I'll assume you've chosen the name setdow.bat for this file in the following discussion.

You will not execute either dow.bat or rundow.bat; these are files created by the script, setdow.bat. Instead, you will run setdow.bat. When setdow.bat finishes, you should be able to type echo %DOW% at the command line, and see the day of the week displayed. You should also be able to type set at the command line and see all of your environment variables, including DOW, SYSDATE and SYSTIME.

So, try this and let me know the results:

(1) put the (revised) code into a file named setdow.bat
(2) at the command line, type: setdow
(3) when the command prompt returns, type: echo %DOW%
(4) when this command completes, type: set

Hope this helps -- additional info appreciated.


----------



## dos1977 (Oct 31, 2003)

Hi,
I am attaching the output screenshot for the code that you have sent me!


----------



## codejockey (Feb 11, 2002)

Well, that's a fairly dramatic failure, isn't it?! )). Could I get a look at setdow.bat? I must have overlooked something there, as well ... except that it works fine for me (of course, what else would I say?!? ).


----------



## dos1977 (Oct 31, 2003)

Did you get a chance to run the Batch file that I have posted before?


----------



## codejockey (Feb 11, 2002)

No, I didn't run the batch file you posted -- did you want me to? I don't understand the point of doing that. I'm certainly willing to take your word that the batch file works with the wday.com executable that you're using, and if that solution works for you, great. All the batch file does is to capture the return value from wday.com, which does the real work of figuring out the day of the week. I was more concerned to find out what problems you were having with the code I posted, as it seems to work fine for me.

If you'd like me to debug whatever's going on, it would be helpful to see what setpow.bat looks like (probably just some dumb oversight on my part, but it doesn't take much ...).


----------



## dos1977 (Oct 31, 2003)

I am attaching the setdow.bat as a jpeg along this mail...Thanks for your help.....Code


----------



## codejockey (Feb 11, 2002)

Thanks for your postings -- definitely gave me the info I was looking for. I should have seen this right away, but for whatever reason, I missed it (my apologies) ...

It appears you are executing the script under NT/XP/Windoze 2000. That's fine, but the script was written to execute under MS-DOS (which is what I thought the environment was going to be, given the information in your posting). The command prompt under Windoze 2000/NT/XP is not the same as a "real" MS-DOS session; the command prompt offers many capabilities not found in MS-DOS and syntax for some commands is different from syntax in MS-DOS. I believe your original screen shot posting reports a "file/command not found" error, and I suspect this is because there is no program named "command" in NT/Windoze2000/XP. Instead, it is named "cmd". Under MS-DOS, the command processor is named command.exe, and that's why the script attempts to run command /c. I'll have a look at revising/porting the script for NT/Windoze 2000/XP; it may be only a matter of changing "command" to "cmd". In the meantime, if you have access to a real DOS environment (say, Windoze 3.1/95/98 that run on top of MS-DOS), you may be able to boot into MS-DOS and run the current version of the script there. 

Hope this helps.


----------



## zephyr (Nov 6, 2003)

XXCOPY can do that and so much more and make it look easy.

http://www.xxcopy.com/xxcopy/index.html#contents

If after doing your homework, you have trouble using the command, visit the Yahoo Group forum that is established for it and you'll get some expert help.

http://groups.yahoo.com/group/xxcopy/

It's freeware and the support is excellent!

Cheers!


----------



## codejockey (Feb 11, 2002)

OK, a quick update ... on my Windoze 2000 system, the script will not execute properly, for at least two reasons:

(1) Windoze 2000 insists on echoing the prompt into the batch file(s) being created.

(2) Windoze 2000 does not perform substitution of the $d and $t parameters when these appear as part of an echo command; instead, the literal $d or $t is echoed.

So, herewith a revised/ported script that works for me on Windoze 2000 under a command prompt window (i.e., cmd.exe):

```
REM determine current date, time and day of week from system clock (Windoze 2000)
@echo off
prompt $s
if not "%2"=="" goto setenv
echo %0 %DATE% > dow.bat
cmd /c dow.bat > rundow.bat           
rundow

:setenv
if exist dow.bat del dow.bat 
if exist rundow.bat del rundow.bat
set DOW=%1
set SYSDATE=%2
prompt
```
Note that the ported script does not set the SYSTIME environment variable, since this value is missing from the %DATE% variable in Windoze 2000. However, the day of the week is still set.

Hope this helps.


----------



## dos1977 (Oct 31, 2003)

I think your code's working and thank you soo much for helping me out...Thanks to Johns too and coderitr!!!
Cheers!


----------



## john1 (Nov 25, 2000)

Cheers,
Glad you got it sorted !

Regards, John


----------



## codejockey (Feb 11, 2002)

Great work! -- glad I was able to help out and you are on track with your programming project. Don't overlook the xxcopy reference, though -- that is one excellent product.


----------

