There are 2 views of this prophecy: 1) Is that it occured in 588BCE, 2 years after Ezekiel made his prophecy(590BCE); which sets the Destruction of Jerusalem at 607BCE, instead of 587BCE. Egypt, being carried off in captivity, and so are those reminants of Jersalem who fled to Egypt in defiance of Jeremiah's prophecy(Jer. 42:15,16,19; 43:10,11) This date would allow for a 40 year captivity period, ending with an alliance of Nabonidus(Babylon) with King Amasis II of Egypt. Since Egypt had already been taken captive-it was reduced to a 'vassal state' by the later date-agreeing with the prophecy of Ezekiel.
However, all of this fails if the Babylonian captivity stated in 568BCE; then Egypt would have only been captive 21 years, and even if there were no alliance between Babylon and Egypt(from the Nebuchnezzar Inscription tablet in the British Museum) Cyrus would have freed ALL captives 8 years later, in 539BCE.
The 2nd view is that it is a future prophecy, waiting to be fulfilled. This answer was taken from Mi Yodeya here
Although Egypt had long ceased from the Age of the Pharoah's of being a world power, there's no conclusive source to prove(or disprove) that one would not be able to walk from one end to the other for 40 years. Given that assertion, it suggests the prophecy would have to wait until the end times to be fulfilled.