The Mathematical structure of all Transforms can be understood by simply first seeing what a Fourier Series Representation is. In Continuous Time Domain, Fourier established that all periodic waveforms can be expressed as sum of Complex exponentials of some magnitude(which are the coefficients in a Fourier Series). The same can actually be applied for an aperiodic waveform assuming a periodic extension of it. So what the underlying Transform Relationships give us are nothing but the Analysis and Synthesis equations for what frequencies are present in a signal and what are their magnitudes. Rather, you can view these magnitudes as the Projections of the signal on the complex exponentials as to trying to figure out how much of a particular frequency is present in a signal. (You might want to remember the Analysis and Synthesis equations to see what I've said here).
Now for a certain set of functions(L2 functions or rather Limited Energy functions $\int_{-\infty}^{\infty}|x^{2}(t)|dt$ being finite and a set of conditions called Dirchlet's conditions being satisfied) have a special and easily identifiable Analysis equation called the Fourier Transform which comes straight from Fourier Representation of Series coefficients. Now in real world, we rarely encounter functions that violate these properties. If a function were to blow up to infinity in Energy we can never use it anyway.
Caution must be exercised because the Fourier representations involve a lot of intricacies which are rather ignored in daily life problem solving. One might learn a lot by looking at Existence, Measurability, Riemann Integrability etc. of functions and their energies.
Once you've tackled the problem of continuous time(both in terms of Series and Transforms) Discrete is just extrapolations right from Nyquist Shannon's sampling theorem. Now what exactly is a digital signal? It is just the sampled version of it. How quickly sampled is what determines the frequency content that you get in the Sampled version. If you look at the formula of a DFT it is nothing but the Analysis equation of Fourier Series represented in $0,1...N-1$ points which are called "Bins". It is nothing but the Discrete version of the Fourier Series(think of Integral in the Analysis equation being replaced by Summation and the $\exp(-j\omega t)$ term in the transform being written as $exp(-2*pi*j*k/N)$ where k represents the number of points that you have from the sampled signal and $2*pi/N$ is nothing but the analogous term in the series which is the Fundamental Angular Frequency. I hope this explains much about how exactly DFT is able to get the Frequencies from a Time domain wave.
And for the last part, for 2 files to have exactly the same amplitude values at exactly the same points of time, it is impossible for them to differ in their frequency content because the Math behind it sees just the values. Maybe I'm misinterpreting your question or your phrasing is not proper.