Your problem of computing the KS distance, i.e.
$$d_{KS}(F_1,F_2)=\sup\{ |F_1(x) - F_2(x)| \mbox{ for } x\in\mathbb{R}\}$$
is very much simplified for empirical data because the emprical CDF is a step function with a finite number of steps. You thus simply need to compare the empirical CDF with the other CDF at the observed data points. Example:
x <- rnorm(50)
# build empirical CDF (beware: returns a FUNCTION)
x.cdf <- ecdf(x)
# compute the maximum of absolute difference at the observed data points
d.KS <- max(abs(x.cdf(x) - pnorm(x)))
print(d.KS)
# for comparison (should yield the same value):
ks.test(x, pnorm)$statistic
If you want to compare two empirical CDFs of two random variables $X$ and $Y$, you must evaluate the difference at the union of data points observed for $X$ and $Y$. Example:
x <- rnorm(50)
y <- rnorm(50)
xy <- c(x,y)
d.KS <- max(abs(ecdf(x)(xy) - ecdf(y)(xy)))