0

I need to get the latest file in a folder. I have the following files in a folder

A1.txt
A2.txt
A3.txt
A4.txt
A5.txt

I need to get the latest file ie A5.txt

i am using the following command to get the latest file.

SET @c = 'dir  /b /o-e ' + QUOTENAME(@Path, '"') + ' A%.txt'  
INSERT INTO #f (Filename)   EXEC master.dbo.xp_cmdshell @C

This will populate all the files to a temp table. I will take the top 1.

is there any simple method to take the latest file

The folder contains doc file also,but i need to take the file startingwith A

4

0 回答 0