Solved

Creating a Batch File for Windows 7

Posted on 2014-03-03
2
518 Views
Last Modified: 2014-04-07
For Example: I’m running a small program in: Pascal called libusers

When the program is run it needs two input files from the user and does some comparison and outputs the result in a text file

So the at Dos prompt I will do the following:
C:\> pascal libusers  -i <file-1> -i <File-2> -o <finalusers.txt>

At present I have to manually type the name of the files everytime I run the program. I want to know if there is a way that I can create a batch file which can automatically pick up the files from a folder and pass them as input to the above program.

The files that I input manually sit in a folder with other files and they all have the same name – I want the batch file to pick the most recent files from that folder.  

Is this possible !!!
0
Comment
Question by:adam_kan2000
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 69

Expert Comment

by:Qlemo
ID: 39900752
"they all have the same name" - that is impossible, as file names are unique. I assume you mean they follow the same pattern in their name.

To automate, you'll need to have strict rules for how to find file1 and file2, and/or to tell how many files (always 2?). Best to list an example folder structure.
0
 
LVL 54

Accepted Solution

by:
Bill Prew earned 500 total points
ID: 39901242
This should do the job, just adjust the folder path in the SET near the top.

@echo off
setlocal

REM Define folder to work in, and output file name
set BaseDir=B:\EE\EE28378812\Files
set File1=
set File2=
set File3=finalusers.txt

REM Make the desired folder the current one
pushd %BaseDir%

REM Find the two most recent files
for /F "tokens=*" %%A in ('dir /b /a-d /o-d "%BaseDir%\*.*"') do (
  if defined File2 goto :GotFiles
  if defined File1 (
    set File2=%%A
  ) else (
    set File1=%%A
  )
)

:GotFiles
REM Run the PASCAL program passing in the file names
ECHO pascal libusers  -i %File1% -i %File2% -o %File3%

REM Return to original folder
popd

Open in new window

~bp
0

Featured Post

Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
A quick Powershell script I wrote to find old program installations and check versions of a specific file across the network.
Learn the basics of strings in Python: declaration, operations, indices, and slicing. Strings are declared with quotations; for example: s = "string": Strings are immutable.: Strings may be concatenated or multiplied using the addition and multiplic…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…

756 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question