Add instance number and display last 5 in men

October 18, 2011 at 14:37:12
Specs: Windows 7
This is a two part questions.

I am needing a way to add an instance number to each file name.

Referencing the code below, i want to start with 1 and have to work it self up each day
(just a note, the %username% and date setting work flawlessly.)

So the first report of the day completed by the user would have the file name
%Username%-%Year%%Month%%Day%_1.pdf

The the second would have the name
%Username%-%Year%%Month%%Day%_2.pdf

and so on, resetting the number count each day.

Here is a part of my current code:

@echo off
mode con:cols=60 lines=35

Set Day=%Date:~-7,2%
Set Month=%Date:~-10,2%
Set Year=%Date:~-4,4%
Set TodayDate=%Year%%Day%%Month%
--snip-- -snip-

copy "\\mcj_pdc\JailReports\MasterForms\JailGeneralIncident.pdf" \\Mcj_pdc\jailreports\Reports\Incident\%Username%-%Year%%Month%%Day%.pdf
start AcroRd32.exe /A "navpanes=0&messages=0" \\Mcj_pdc\jailreports\Reports\Incident\%Username%-%Year%%Month%%Day%.pdf
goto menu

The secont part of my questions ..

I want a menu that would display the last 6 reports taken, starting with the last one done (based on %username% and date and setting that to a variable I can pull up when they select that option.

The menu would look like:

1) Create New Indident (From above question)
2) JTesting-20111007_3.pdf
3) JTesting-20111007_2.pdf
4) JTesting-20111007_1.pdf
5) JTesting-20111006_2.pdf


See More: Add instance number and display last 5 in men

Report •


#1
October 18, 2011 at 20:34:25
I apologize for cutting this short, but I don't have time to finish it... this should get you going...

@echo off
setlocal enabledelayedexpansion
mode con:cols=60 lines=35

Set Day=%Date:~-7,2%
Set Month=%Date:~-10,2%
Set Year=%Date:~-4,4%
Set TodayDate=%Year%%Day%%Month%

dir /b /oD c:\reports_directory\%username%*.* > dircontents.tmp

REM ***Right here you need to enter code to trim everything out of dircontents.tmp except for the last 6 lines

set num=1
for /f (tokens=*) %%a in (dircontents.tmp) do (
set file!num!=%%a
set /a num=!num!+1
)

echo 1) Create New Incident
echo 2) %file1%
echo 3) %file2%
echo 4) %file3%
echo 5) %file4%
echo 6) %file5%
echo 7) %file6%

set /p choice=Please enter the number of your choice:

if '%choice%'=='1' goto 1
if '%choice%'=='2' goto 2
if '%choice%'=='3' goto 3
if '%choice%'=='4' goto 4
if '%choice%'=='5' goto 5
if '%choice%'=='6' goto 6
if '%choice%'=='7' goto 7


if exist c:\reports_directory\%username%-%TodayDate%_*.pdf goto incrementfile

:incrementfile

:1

:2

:3

:4

:5

:6

:7


Report •
Related Solutions


Ask Question