io.file refactoring and handle special cases in cd_previous