ABXZone Computer  Forums



Welcome to the ABXZone Computer Forums forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact contact us.

Reply
 
LinkBack Thread Tools Display Modes
Old 09-02-2004, 09:30 AM   #1
~Not an Expert~
 
jcash's Avatar
 
Join Date: May 2002
Posts: 1,678
Exclamation .BAT file programming help needed

Hello again my friends at ABXZONE. It's been a while since my last visit, but I've come to depend on the experts here to help, when no other help is available.

I am trying to convert an OS/2 command file (.CMD) to work on Win9x, Win2k and WinXP. The problem is that with OS/2, there are functions (via REXX) that are not available in standard windows .BAT files. To further complicate things, utility programs (XBATCH, KIX, etc) cannot be loaded on the Windows machines.

PROBLEM: Copy file <anyfile>.DAT file to a sub-directory for archiving. There is the possibility that this .BAT file will be run multiple times in one day, so the filename must be unique with each execution.

The OS/2 REXX (.CMD) file, took the current date and time, removed the "/" from the date and the ":" from the time, and made the filename with what is left....example 09022004082637.DAT = MMDDYYYYHHMMSS.DAT.

I have been able to put the current date and time into varables, but haven't been sucessfull in removing the "/" and ":" to make a valid filename.

If you have any tricks or tips to do string manipulation in standard Windows .BAT files, PLEASE provide examples if you can.

Jim
__________________
[ABX]-Kahn - "Keepin' Time!"
(Offline)   Reply With Quote

Advertisement [Remove Advertisement]

Old 09-02-2004, 09:49 AM   #2
Registered User
 
Logan_abx's Avatar
 
Join Date: Jan 2003
Location: Blue Ridge Mountains, VA
Posts: 384
Date/Time parsing

jcash,

If you have command extensions enabled (by default, they are) on Windows XP or Windows 2000, the following will work to create the file name you're looking for.

Code:
@echo off for /F "tokens=2,3,4 delims=/ " %%a in ('echo %DATE%') DO set HDATE=%%a%%b%%c for /f "tokens=1,2,3 delims=:. " %%a in ('echo %TIME%') DO set HTIME=%%a%%b%%c set HFILENAME=%HDATE%%HTIME%.dat echo %HFILENAME%
(Offline)   Reply With Quote
Old 09-02-2004, 10:05 AM   #3
~Not an Expert~
 
jcash's Avatar
 
Join Date: May 2002
Posts: 1,678
Thanks for the quick reply!

I tried this code on a Windows 98SE machine and get a Syntax error. I'm not sure exactly how this should work, but let me take a guess.

It is trying to "token-ize" the results of 'ECHO %time%' using the ":" as a deliminator. I don't see how the variables %b and %c are set or what the "/f" does. Perhaps it won't work on Win98?

Thanks

Jim

EDIT: it works perfectly in WINXP.....
__________________
[ABX]-Kahn - "Keepin' Time!"
(Offline)   Reply With Quote
Old 09-02-2004, 10:07 AM   #4
Linux user
 
yamawho's Avatar
 
Join Date: Jul 2002
Location: Montreal
Posts: 4,074
Can't help you with this one ... I just wanting to say hi
__________________
(Offline)   Reply With Quote
Old 09-02-2004, 11:16 AM   #5
Registered User
 
Logan_abx's Avatar
 
Join Date: Jan 2003
Location: Blue Ridge Mountains, VA
Posts: 384
Ooops.

Jim,

It won't work on 98. Several of the features used here are command extensions added in NT/2000. I missed the bit in your message where you needed it to work under 98. Sorry about that.

That said, Windows 98 is a lot more difficult. The batch language on that particular OS is as crippled as it gets. I HAVE seen date and time parsers that didn't use any external process for Windows 98, but they're nasty, and would have to be customized (if you can follow the obfuscated batch code) for what you want. You can look here: http://www.pressroom.com/~tglbatch/pdate.html for something that works (supposedly -- I have no way to test it) in Windows 98.

Personally, I'd create a very small program that you can execute that will write out the correct formatted date and time to stdout.

Oh yes -- how the original works. When you do a for /f, you invoke a parser that processes each line of input (if there were multiple lines returned by the command, each one would be processed). The variable name you pass is actually the FIRST name, which gets the value of the first parsed token. Each subsequent parsed token goes to name+1 (character wise). So, if you use %%x, the variables would be x, y and z.

Under XP or Windows 2000, you can just type in 'help for' at the command line, and it will show you the syntax information for this.

Logan
(Offline)   Reply With Quote
Old 09-02-2004, 12:29 PM   #6
The Shade of Lazarus
 
KingTermite's Avatar
 
Join Date: Jun 2002
Location: PM me to keep in contact
Posts: 26,003
Sorry Jim....I didn't get here until late in the game.

I think the link Logan posted will work well...it claims to work with Win98. If you take that and either use the parsed date/time to append to each file name or create a subdirectory with that name to copy files in to you should be good I think.
__________________

Bye Bye ABXZone.....Rest In Peace.
(Offline)   Reply With Quote
Old 09-02-2004, 01:02 PM   #7
Registered User
 
Join Date: Jul 2004
Location: Indiana
Posts: 63
Exclamation

For a scripting language that works on Win9x and up, check out Kixtart:

http://www.kixtart.org/

Plenty of examples and such there. If you need further help with it, just ask

Also, REXX for Windows:
http://www.quercus-sys.com/prexxw35.htm
(Offline)   Reply With Quote
Old 09-02-2004, 01:08 PM   #8
The Shade of Lazarus
 
KingTermite's Avatar
 
Join Date: Jun 2002
Location: PM me to keep in contact
Posts: 26,003
Quote:
Originally Posted by chrisd
For a scripting language that works on Win9x and up, check out Kixtart:

http://www.kixtart.org/

Plenty of examples and such there. If you need further help with it, just ask

Also, REXX for Windows:
http://www.quercus-sys.com/prexxw35.htm
Good Point....I had forgotten there was a REXX version for Windows. If you want to install scripting engines, then I'd put Perl (ActivePerl) on the machine(s) and have Perl Scripts.
__________________

Bye Bye ABXZone.....Rest In Peace.
(Offline)   Reply With Quote
Old 09-02-2004, 09:06 PM   #9
~Not an Expert~
 
jcash's Avatar
 
Join Date: May 2002
Posts: 1,678
Hello Yamawho. Glad to see you are still here.
Thanks to Logan and ChrisD and the "King Termite" for your replies....

but...(there is always a butt, and it's usually me)...but

I can't add any scripting language processors to these machines, and "whatever" must work with Win98, Win2K, and WinXP without modification....That said, I came up with a solution...it will even work in DOS, and OS/2.

I used an inline QBASIC program (Qbasic was distributed by Microsoft on the Windows Resource Kits, so our corporate watchdogs with their fancy detection software bypassed it). If anyone is interested in the code, I can post it on Friday.
__________________
[ABX]-Kahn - "Keepin' Time!"
(Offline)   Reply With Quote
Old 09-03-2004, 07:03 AM   #10
Registered User
 
Logan_abx's Avatar
 
Join Date: Jan 2003
Location: Blue Ridge Mountains, VA
Posts: 384
QBasic

Jim,

QBasic isn't distributed as part of XP, though... I know you can install it by copying it off of a 98 CD, but this isn't that much different from installing REXX, or a simple time utility.

Logan
(Offline)   Reply With Quote
Old 09-03-2004, 08:29 AM   #11
~Not an Expert~
 
jcash's Avatar
 
Join Date: May 2002
Posts: 1,678
I didn't actually "INSTALL" QBASIC on any machine. We have a common "SOFTWARE" network share that now has the "QBASIC.EXE and QBASIC.HLP" files. In my .BAT procedure, I just execute QBASIC from the utility directory on the server, and don't load it on each machine. This snip of code sets an enviornment variable "FILENAME" to be MMDDYYYHHMMSS.DAT.

Code:
SET PGMPATH=C:\DATAFILES :: Make the QBASIC script type %0 | find " " | > %PGMPATH%\FNAME.BAS :: Run the script F:\UTILITY\qbasic.exe /run %PGMPATH%\FNAME.BAS :: Run the batch file created by the QBASIC script to set FILENAME variable CALL %PGMPATH%\FNAME.BAT COPY %PGMPATH%\CTCORD.DAT %PGMPATH%\LOGS\%FILENAME% ERASE %PGMPATH%\FNAME.BAS ERASE %PGMPATH%\FNAME.BAT goto DONE :QBASIC :: All QBASIC code MUST be indented four or more spaces. :: NOTHING else in this batch file may be indented four spaces. DIM HH AS STRING DIM MM AS STRING DIM SS AS STRING DIM MO AS STRING DIM DD AS STRING DIM YYYY AS STRING MO = MID$(DATE$,1,2) DD = MID$(DATE$,4,2) YYYY = MID$(DATE$,7,4) HH = MID$(TIME$,1,2) MM = MID$(TIME$,4,2) SS = MID$(TIME$,7,2) OPEN "FNAME.BAT" FOR OUTPUT AS #1 PRINT #1, "SET FILENAME=" + MO + DD + YYYY + HH + MM + SS + ".DAT" CLOSE #1 SYSTEM :DONE
Thanks Again, and I'll try to frequent ABXZONE more often.
__________________
[ABX]-Kahn - "Keepin' Time!"
(Offline)   Reply With Quote
Old 09-04-2004, 10:43 AM   #12
 
Join Date: Jan 2004
Posts: 605
Holy crap, there's a lot of extra stuff the FOR command can do under XP. Shame I didn't have that power in the DOS/Win9x days! Nowadays of course for repetive functions and stuff I just write stuff in VB.
__________________
OS Microsoft Windows XP Professional Service Pack 2
CPU Intel Pentium 4 3.0 GHz with HT (Northwood) Motherboard ASUS P4P800 Deluxe
RAM 1 GB Kingston DDR400 3-3-3-8 Dual Channel
Display NVIDIA GeForce 6600 GT 256 MB AGP Monitor 17" Mitsubishi Diamond View 1770 FD
Sound SoundMAX Digital Audio Speakers DKL 3D-650
NIC 3Com Gigabit LOM Modem Marconi FLX Stream-ISG
HDD Maxtor DiamondMax Plus 9 120 GB HDD Maxtor DiamondMax Plus 9 200 GB
Optical SONY CRX300E CD-RW/DVD-ROM Optical SONY DWD18A DVD±RW
Case AOpen KF45A-P4 PSU LC-B400ATX
Keyboard Microsoft Internet Keyboard Mouse Microsoft Wheel Mouse Optical
(Offline)   Reply With Quote
Old 09-04-2004, 10:49 AM   #13
Registered User
 
Logan_abx's Avatar
 
Join Date: Jan 2003
Location: Blue Ridge Mountains, VA
Posts: 384
Quote:
Originally Posted by Darkfalz
Holy crap, there's a lot of extra stuff the FOR command can do under XP. Shame I didn't have that power in the DOS/Win9x days! Nowadays of course for repetive functions and stuff I just write stuff in VB.
Try looking at all of the new stuff the SET command can do. It can prompt a user for an entry, extract substrings, perform math, do string replacements. I think Microsoft noticed that every other operating system had a real batch processing language, and tried to 'hack' in a few features.

Logan
(Offline)   Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



Powered by vBulletin® Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.1
vBulletin Skin developed by: vBStyles.com