In this paper, we study the relay selection problem for a finite buffer-aided decode-and-forward cooperative wireless network. A relay selection policy that fully exploits the flexibility offered by the buffering ability of the relay nodes in order to maximize the achieved diversity gain is investigated. This new scheme incorporates the instantaneous strength of the wireless links as well as the status of the finite relay buffers and adapts the relay selection decision on the strongest available link by dynamically switching between relay reception and transmission. In order to analyse the new relay selection policy in terms of outage probability and diversity gain, a theoretical framework that models the evolution of the relay buffers as a Markov chain (MC) is introduced. The construction of the state transition matrix and the related steady state of the MC are studied and their impact on the derivation of the outage probability is investigated. We show that the proposed relay selection scheme significantly outperforms conventional relay selection policies for all cases and ensures a diversity gain equal to two times the number of relays for large buffer sizes.