An approach for measuring the focal length of a lens using a diffractive beam sampler is presented. The high-precision measurement of the focal length is conducted while a specimen is continuously moved along the optical axis. Images of the fractional beam spots on a charge-coupled-device camera are tracked with respect to the position of the specimen to obtain the relation between the beam-spot distance and the lens-specimen distance. Accordingly, this relation can be used to infer the focal length via computation. The method is carried out by simulation, easy, and inexpensive. In addition, it is applicable to find the focal length of a thin lens as well as the effective focal length of a system of lenses because it does not require the movement or replacement of lenses. The results indicate a dramatically high precision.