Here in a nutshell this is what I'm trying to do:
output a directory listing, easy enough.
dir /B > listing.txt
But, inside that listing I need to search and replace so lines that
have the .PDF extension, with two sets of dates. the end product would
go from something like this..
123456.pdf
To this..
123456,,,(tomorrow'sdate),(tomorrow'sdate + 6 days)
IE
123456,,,2/12/2005,2/18/2005
and would eventually be a .csv file.
I know there is an NT4 Resource kit that has a "munge.exe", which I
could easily accomplish what I'm trying to do, but I'd have to modify
the dates all the time. Any easier solutions? I have limited batch
scripting experience so I have a decent grasp of the concepts. Any
input would be greatly appreciated.
Adam
The tricky part is getting the "tomorrow'sdate + 6 days" into an
environment variable. The rest is rather straight standard cmd.exe
scripting.
31} How many days ago was 31.12.2003? What date was it 100 days ago?
111572 Jan 22 2005 ftp://garbo.uwasa.fi/pc/link/tscmd.zip
tscmd.zip Useful NT/2000/XP script tricks and tips, T.Salmi
Windows Command Line Interface script programming links
http://www.uwasa.fi/~ts/http/http2.html#cmdscript
All the best, Timo
--
Prof. Timo Salmi ftp & http://garbo.uwasa.fi/ archives 193.166.120.5
Department of Accounting and Business Finance ; University of Vaasa
mailto:t...@uwasa.fi <http://www.uwasa.fi/~ts/> ; FIN-65101, Finland
Timo's FAQ materials at http://www.uwasa.fi/~ts/http/tsfaq.html
::pdf2csv.cmd::::::::::::::::::::::::::::::::::::::::::::::::::::::::
@echo off&setlocal
call :GetDate yy mm dd
call :DateToDays %yy% %mm% %dd% Today
set /A Tomorrow=%Today%+1
set /A NextWeek=%Today%+7
call :DaysToDate %Tomorrow% yy2 mm2 dd2
call :DaysToDate %NextWeek% yy3 mm3 dd3
set Tomorrow=%mm2%/%dd2%/%yy2%
set NextWeek=%mm3%/%dd3%/%yy3%
::
for %%A in (*.pdf) do echo/%%~nA,,,%Tomorrow%,%NextWeek%
::
goto :eof
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: Download and append these functions from Ritchies Library:
:GetDate yy mm dd
:: http://www.commandline.co.uk/lib/Batch%20Function%20Library/Date%20and%20Time%20Functions/GetDate.html
:DateToDays %yy% %mm% %dd% days
:: http://www.commandline.co.uk/lib/Batch%20Function%20Library/Date%20and%20Time%20Functions/DateToDays.html
:DaysToDate %days% yy mm dd
:: http://www.commandline.co.uk/lib/Batch%20Function%20Library/Date%20and%20Time%20Functions/DaysToDate.html
HTH
--
Gruesse Greetings Saludos Saluti Salutations
Matthias
---------+---------+---------+---------+---------+---------+---------+
Very readily done if VBScript is used - this shows the basics
type $4.vbs
N = Now
wscript.echo "set D1=" & Int(N+1)
wscript.echo "set D6=" & Int(N+6)
cscript //nologo $4.vbs
set D1=2005-02-13
set D7=2005-02-19
so redirect cscript output to file and execute; and package the lot into
one file by the usual tricks. That will also work in Win98.
That should set the localised date; see in
<URL:http://www.merlyn.demon.co.uk/vb-dates.htm> for other specific
formats, though it should be obvious enough.
IIRC, VBScript can set the environment variables directly,
--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 MIME. ©
Web <URL:http://www.merlyn.demon.co.uk/> - w. FAQish topics, links, acronyms
PAS EXE etc : <URL:http://www.merlyn.demon.co.uk/programs/> - see 00index.htm
Dates - miscdate.htm moredate.htm js-dates.htm pas-time.htm critdate.htm etc.
Thanks for your solution, just one question. I'll use the word
'amateur' to describe my experience with scripting however where (or
for what) does the cmd file look to search and replace through? I've
been calling my directory listings 'dir.txt' but that really has no
restriction.
Thanks again.
-A
for %%A in (*.pdf) do echo/%%~nA,,,%Tomorrow%,%NextWeek%
To use a folder passed as an argument it's better to parse dir output,
and to output to a file instead of screen use rediection
replace the above line ewith these statements:
:: default to current dir, else use first argument to check for pdf'S
set folder=%~1
if NOT defined folder set folder=%cd%
:: output goes to :
set outfile=yourfile.csv
:: delete file if already present.
del /Q %Outfile% >NUL 2>&1
for /f "delims=" %%A in (
'dir /B /A-D "%folder%\*.pdf"'
) do echo/%%~nA,,,%Tomorrow%,%NextWeek% >>%Outfile%
::