Getting the inverse of drupal_realpath (Drupal 7) I know drupal_realpath is depreciated but as far as I can tell I cannot avoid using it.  

I have a little module that will unzip a file and search the contents of the unzipped file and create content with the images it finds.  In order to search the unzipped directory tree I need to rely on standard php methods will not work with paths like 'public://..." so I need to use drupal_realpath to massage my paths into something drupal can handle. 

When I actually create the image file I do not want to use the drupal realpath because this would obviously be problematic if I migrated to a different server.  

Is there a way I can turn the realpath which will look something like this:

/Applications/MAMP/htdocs/drupal/sites/default/files/my_file.png


back into something like:

public://my_file.png


If not is there some way I can search a directory structure without using drupal_realpath?

EDIT:
So it seems that my problem may really only be with certain PHP lirbaries for example simpleXML.

$shape_xml = 'public://Arcade Projects/ender2012/AgentCubes/Open Arcade/Moonsweeper/version8/Moonsweeper/agents/Tutorial/shapes/Tutorial/shape.xml';

watchdog("file exists normal",file_exists($shape_xml));
watchdog("file exists real path",file_exists(drupal_realpath($shape_xml)));


In the above example, both watchdogs print 1, so it seems that file_exists works fine with the drupal path or the realpath.

But, if I call simplexml_load_file with the drupal_realpath like this:

$xml = simplexml_load_file(drupal_realpath($shape_xml));


everything works fine.

But If I call it like this:

$xml = simplexml_load_file($shape_xml);


I get the following error:

Notice: Trying to get property of non-object in harvest_icons() (line 775 of /Applications/MAMP/htdocs/drupal/sites/all/modules/custom/unzip/unzip.module).
It's not pretty but this will reverse engineer such a path quite reliably:

$old_path = '/Applications/MAMP/htdocs/drupal/sites/default/files/my_file.png';

$doc_root = $_SERVER['DOCUMENT_ROOT'] . '/';

$public_file_path = variable_get('file_public_path', 'sites/default/files') . '/';

$replace = array($doc_root, $public_file_path);

$new_path = 'public://' . str_replace($replace, '', $old_path);