Computing.Net > Forums > Disk Operating System > dir command to select first file

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.

dir command to select first file

Reply to Message Icon

Name: raghav525
Date: March 16, 2009 at 14:27:03 Pacific
OS: Windows XP
Subcategory: General
Comment:

Is there any way to use the dir command to select first file of similar pattern of files
In unix,
ls /u01/opt/incoming/abc_*.txt | head -1

something like
dir /O D:\Infa\incoming\abc_*.txt ???

Thanks for your help



Sponsored Link
Ads by Google

Response Number 1
Name: DAVEINCAPS
Date: March 16, 2009 at 16:29:04 Pacific
Reply:

I suppose it depends on what 'pattern' you want to sort by. You can list by name, date, extension, attributes, and size.. Just type dir/? and enter at the dos prompt for more info.


0

Response Number 2
Name: raghav525
Date: March 16, 2009 at 19:58:13 Pacific
Reply:

Actually, I want to select only the fist file for example, one directory has 5 files
abc_0001.txt
abc_0002.txt
abc_0003.txt
abc_0004.txt
abc_0005.txt
by use single command i would like to select first file abc_0001.txt

in unix, we use command:
ls /u01/opt/incoming/abc_*.txt | head -1

i just wondering is ther any similar command in windows?
Thanks!


0

Response Number 3
Name: DAVEINCAPS
Date: March 16, 2009 at 20:35:05 Pacific
Reply:

If you want to use the DIR command and have only one file show up then you're going to have to know what name variations all the files can take. Or use the DIR command on its exact file name--dir abc_0001.txt. But that seems kind of silly.

In the above list of files dir/o:n will list the files in order with abc_0001.txt being first.

Using wildcards there are several ways the DIR command will return just abc_0001.txt.

dir abc_???1.txt
dir ???_???1.txt
dir a??_???1.txt
dir ab?_??01.txt

etc.

where the question mark means 'any alphanumeric character'. I think the underline ( - ) has to be there and can't be replaced by a wildcard. How you use the wildcards depends on what you know about all the files.

In dos a wildcard can replace an alphanumberic character. The asterisk ( * ) replaces an entire file name or its extension. For example *.* means 'any file name with any extension'. *.txt means 'any file name with a txt extension'. abc.* means 'a file named abc with any extension'.


0

Response Number 4
Name: raghav525
Date: March 17, 2009 at 06:58:10 Pacific
Reply:

Thanks!
When i issue a command, i would to have the return value as only the first file (abc_0001.txt.). Assume i sort all the file as mentioned.


0

Response Number 5
Name: DAVEINCAPS
Date: March 17, 2009 at 12:10:12 Pacific
Reply:

If you knew all the files started with ABC then you could use something like dir abc_???1.txt or dir ???_???1.txt. Both would return only that one file.

However if, for example, some of the files started with XYZ then something like dir ???_0001.txt would also return XYZ_0001.txt (if it existed)

How you use the wildcards depends on what you know about the other file names in the directory. The more you know about them the better you can use wildcards to isolate the one file you want to show.


0

Related Posts

See More



Sponsored Link
Ads by Google
Reply to Message Icon





Use following form to reply to current message:

Login or Register to Reply
LoginRegister


Sponsored links

Ads by Google


Results for: dir command to select first file

How to rescue my files on C:\ in DOS? www.computing.net/answers/dos/how-to-rescue-my-files-on-c-in-dos/7935.html

Looking for DOS Command to search a file on C drive www.computing.net/answers/dos/looking-for-dos-command-to-search-a-file-on-c-drive/5109.html

Older 386 PC www.computing.net/answers/dos/older-386-pc/1030.html