Computing.Net > Forums > Programming > Simple Batch file Help.

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Simple Batch file Help.

Reply to Message Icon

Name: aha
Date: June 2, 2008 at 23:51:55 Pacific
OS: winxp
CPU/Ram: P4 2.2Ghz
Product: Intel
Comment:

Hi M2 Master,

I just want to ask a simple question.
In order to grab the latest TXT file's name,
I use the following code. If in current folder,
I have more than one TXT file, how can I get the first line infor?

for /f "tokens=* delims= " %%d in ('dir /b/o- *.txt') do (
set latest=%%d
)

Result:
dir *.txt /b/o-
F:\txt2pdf>dir *.txt /b /o-
ledger_gr52.txt
ledger_gr53.txt
null.txt

The Var latest will be "null.txt", not "ledger_gr52.txt".

Could you please help me how to get the first line infor?

Thanks.

Phil

Computer Programmer



Sponsored Link
Ads by Google

Response Number 1
Name: aha
Date: June 3, 2008 at 01:46:43 Pacific
Reply:

Hi M2,

I figured out the DIR command should like following.

for /f "tokens=* delims= " %%d in ('dir - /b/o- *.txt') do (
set latest=%%d
)

Thanks.

Phil

Computer Programmer


0

Response Number 2
Name: Mechanix2Go
Date: June 3, 2008 at 04:28:49 Pacific
Reply:

@echo off
setLocal EnableDelayedExpansion

for /f "tokens=* delims= " %%a in ('dir/b/a-d/od *.txt') do (
set last=%%a
)
echo last is !last!


=====================================
If at first you don't succeed, you're about average.

M2


0

Response Number 3
Name: aha
Date: June 3, 2008 at 21:07:35 Pacific
Reply:

Hi Mechanix2Go,

Thanks for your code.

You are the best.

Regards,
Phil

Computer Programmer


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Simple Batch file Help.

Simple Batch file www.computing.net/answers/programming/simple-batch-file/10948.html

Batch file help. www.computing.net/answers/programming/batch-file-help/8079.html

DOS Batch File Help? www.computing.net/answers/programming/dos-batch-file-help/15613.html