tags:

views:

290

answers:

2

How to copy the first file in any directory starting with .rar extension?

A: 

Define first: Sorted by date? By name?

Esteban Araya
Define what first ?
Murtaza RC
does not matter any sorting is fine.
Murtaza RC
He is asking what you mean by "First". First file when they are sorted by date? or first when sorted alphabetically?
John T
As I mentioned the order does not matter.
Murtaza RC
+4  A: 

This will copy "the first .rar" file found" (randomly selected, for all I know) in the current folder to C:\Temp. I'd consider this to be a template you can start with.

@ECHO OFF
CLS

FOR %%A in (*.rar) do (
   COPY %%A  C:\temp
   GOTO :Exit
)

:Exit
Philip Kelley
How is a random file the first file? :)
Esteban Araya
Technically, it is not random. However, since (with this particular script) we have no real control over what file is the first file listed by the OS, we can assume nothing about which file will be the first returned, so it might as well be random.
Philip Kelley