document.write('<div class="c" style="font-family: monospace;"><br />');
document.write('<span style="color: #339933;">#include &lt;io.h&gt;</span><br />');
document.write('<br />');
document.write('<span style="color: #808080; font-style: italic;">/** quick check for file using findfirst */</span><br />');
document.write('<span style="color: #993333;">static</span> <span style="color: #993333;">int</span> AP_FileExists<span style="color: #66cc66;">&#40;</span><span style="color: #993333;">const</span> <span style="color: #993333;">char</span> * file<span style="color: #66cc66;">&#41;</span><br />');
document.write('<span style="color: #66cc66;">&#123;</span> <br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #993333;">struct</span> _finddata_t myFinddata;<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #993333;">long</span> hFile;<br />');
document.write('<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #993333;">int</span> ok = <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span>hFile = _findfirst<span style="color: #66cc66;">&#40;</span> file, &amp;myFinddata <span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> != -1L<span style="color: #66cc66;">&#41;</span>;&nbsp; &nbsp; <br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>ok<span style="color: #66cc66;">&#41;</span> _findclose<span style="color: #66cc66;">&#40;</span>hFile<span style="color: #66cc66;">&#41;</span>;<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">return</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span>ok<span style="color: #66cc66;">&#41;</span> &amp;&amp; <span style="color: #66cc66;">&#40;</span>!<span style="color: #66cc66;">&#40;</span>myFinddata.<span style="color: #202020;">attrib</span>&amp;_A_SUBDIR<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> ; &nbsp; &nbsp; <br />');
document.write('<span style="color: #66cc66;">&#125;</span><br />');
document.write('<br />');
document.write('<span style="color: #808080; font-style: italic;">/** quick check for directory using findfirst */</span><br />');
document.write('<span style="color: #993333;">static</span> <span style="color: #993333;">int</span> AP_DirExists<span style="color: #66cc66;">&#40;</span><span style="color: #993333;">const</span> <span style="color: #993333;">char</span> * dir<span style="color: #66cc66;">&#41;</span><br />');
document.write('<span style="color: #66cc66;">&#123;</span><br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>!dir<span style="color: #66cc66;">&#41;</span> <span style="color: #b1b100;">return</span> <span style="color: #cc66cc;">0</span>; <span style="color: #808080; font-style: italic;">// watch it, it\'s a pointer</span><br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #993333;">struct</span> _finddata_t myFinddata;<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #993333;">long</span> hFile;&nbsp; &nbsp; &nbsp;<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; <br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// may be called with trailing \'\\\'</span><br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #993333;">int</span> length = strlen<span style="color: #66cc66;">&#40;</span>dir<span style="color: #66cc66;">&#41;</span>;<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>dir<span style="color: #66cc66;">&#91;</span>length<span style="color: #cc66cc;">-1</span><span style="color: #66cc66;">&#93;</span>==<span style="color: #ff0000;">\'<span style="color: #000099; font-weight: bold;">\\</span>\'</span><span style="color: #66cc66;">&#41;</span><br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #993333;">char</span>* buf = new <span style="color: #993333;">char</span> <span style="color: #66cc66;">&#91;</span>length<span style="color: #cc66cc;">+1</span><span style="color: #66cc66;">&#93;</span>;<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; strcpy<span style="color: #66cc66;">&#40;</span>buf,dir<span style="color: #66cc66;">&#41;</span>; buf<span style="color: #66cc66;">&#91;</span>length<span style="color: #cc66cc;">-1</span><span style="color: #66cc66;">&#93;</span>=<span style="color: #cc66cc;">0</span>;<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #993333;">int</span> ok = <span style="color: #66cc66;">&#40;</span> <span style="color: #66cc66;">&#40;</span>hFile = _findfirst<span style="color: #66cc66;">&#40;</span> buf, &amp;myFinddata <span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> != -1L <span style="color: #66cc66;">&#41;</span>;&nbsp; &nbsp;&nbsp; &nbsp;<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _findclose<span style="color: #66cc66;">&#40;</span>hFile<span style="color: #66cc66;">&#41;</span>;<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; delete <span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">&#93;</span> buf;<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">return</span> <span style="color: #66cc66;">&#40;</span>ok &amp;&amp; <span style="color: #66cc66;">&#40;</span>myFinddata.<span style="color: #202020;">attrib</span>&amp;_A_SUBDIR<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>; &nbsp; <br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">else</span><br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #993333;">int</span> ok = <span style="color: #66cc66;">&#40;</span> <span style="color: #66cc66;">&#40;</span>hFile = _findfirst<span style="color: #66cc66;">&#40;</span> dir, &amp;myFinddata <span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> != -1L <span style="color: #66cc66;">&#41;</span>;&nbsp; &nbsp;<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>ok<span style="color: #66cc66;">&#41;</span> _findclose<span style="color: #66cc66;">&#40;</span>hFile<span style="color: #66cc66;">&#41;</span>;<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">return</span> <span style="color: #66cc66;">&#40;</span>ok &amp;&amp; <span style="color: #66cc66;">&#40;</span>myFinddata.<span style="color: #202020;">attrib</span>&amp;_A_SUBDIR<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;&nbsp; &nbsp;<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />');
document.write('<span style="color: #66cc66;">&#125;</span><br />');
document.write('<br />');
document.write('<span style="color: #808080; font-style: italic;">/** check for drive with drive mask function */</span><br />');
document.write('<span style="color: #000000; font-weight: bold;">inline</span> bool AP_DriveExists<span style="color: #66cc66;">&#40;</span><span style="color: #993333;">const</span> <span style="color: #993333;">char</span>* path<span style="color: #66cc66;">&#41;</span><br />');
document.write('<span style="color: #66cc66;">&#123;</span><br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>path==<span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span> <span style="color: #b1b100;">return</span> <span style="color: #000000; font-weight: bold;">false</span>;&nbsp; &nbsp; &nbsp; <br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>path<span style="color: #66cc66;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#93;</span>==<span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span> <span style="color: #b1b100;">return</span> <span style="color: #000000; font-weight: bold;">false</span>;<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>strlen<span style="color: #66cc66;">&#40;</span>path<span style="color: #66cc66;">&#41;</span>&lt;<span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#41;</span> <span style="color: #b1b100;">return</span> <span style="color: #000000; font-weight: bold;">false</span>;&nbsp; &nbsp; &nbsp; &nbsp;<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>path<span style="color: #66cc66;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#93;</span>!=<span style="color: #ff0000;">\':\'</span><span style="color: #66cc66;">&#41;</span> <span style="color: #b1b100;">return</span> <span style="color: #000000; font-weight: bold;">true</span>; &nbsp;&nbsp;&nbsp;<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; <br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #993333;">unsigned</span> <span style="color: #993333;">long</span> uDriveMask = _getdrives<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #993333;">int</span> index = tolower<span style="color: #66cc66;">&#40;</span>path<span style="color: #66cc66;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span>-<span style="color: #ff0000;">\'a\'</span>;<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">return</span> <span style="color: #66cc66;">&#40;</span>uDriveMask &amp; <span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span> &lt;&lt; index<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>!=<span style="color: #cc66cc;">0</span>;&nbsp; <br />');
document.write('<span style="color: #66cc66;">&#125;</span><br />');
document.write('<br />');
document.write('<span style="color: #808080; font-style: italic;">/** make sure path exists (recursive). <br />');
document.write('&nbsp; * must have a \'\'\\\' behind the last entry */</span><br />');
document.write('<span style="color: #993333;">static</span> bool AP_MakePath<span style="color: #66cc66;">&#40;</span><span style="color: #993333;">const</span> <span style="color: #993333;">char</span> *path<span style="color: #66cc66;">&#41;</span> <br />');
document.write('<span style="color: #66cc66;">&#123;</span><br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>!path<span style="color: #66cc66;">&#41;</span> <span style="color: #b1b100;">return</span> <span style="color: #cc66cc;">0</span>; <span style="color: #808080; font-style: italic;">// watch it, it\'s a pointer</span><br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #993333;">char</span> dir<span style="color: #66cc66;">&#91;</span><span style="color: #cc66cc;">1024</span><span style="color: #66cc66;">&#93;</span>;<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; strcpy<span style="color: #66cc66;">&#40;</span>dir,path<span style="color: #66cc66;">&#41;</span>;<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #993333;">char</span> *p = strrchr<span style="color: #66cc66;">&#40;</span>dir,<span style="color: #ff0000;">\'<span style="color: #000099; font-weight: bold;">\\</span>\'</span><span style="color: #66cc66;">&#41;</span>;<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>p!=<span style="color: #000000; font-weight: bold;">NULL</span><span style="color: #66cc66;">&#41;</span> <br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; *p=<span style="color: #cc66cc;">0</span>;<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>strlen<span style="color: #66cc66;">&#40;</span>dir<span style="color: #66cc66;">&#41;</span>&lt;<span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#41;</span> <span style="color: #b1b100;">return</span> <span style="color: #000000; font-weight: bold;">true</span>;&nbsp;&nbsp;<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>!AP_DirExists<span style="color: #66cc66;">&#40;</span>dir<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; AP_MakePath<span style="color: #66cc66;">&#40;</span>dir<span style="color: #66cc66;">&#41;</span>; <span style="color: #808080; font-style: italic;">// create previous, if neccesary</span><br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _mkdir<span style="color: #66cc66;">&#40;</span>dir<span style="color: #66cc66;">&#41;</span>;&nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// create this</span><br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span>&nbsp; &nbsp; &nbsp; &nbsp;<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">return</span> <span style="color: #000000; font-weight: bold;">true</span>;<br />');
document.write('<span style="color: #66cc66;">&#125;</span><br />');
document.write('<br />');
document.write('<span style="color: #808080; font-style: italic;">/** remove path recusively.<br />');
document.write('&nbsp; * will remove only empty directories */</span><br />');
document.write('<span style="color: #993333;">static</span> bool AP_RemovePath<span style="color: #66cc66;">&#40;</span><span style="color: #993333;">const</span> <span style="color: #993333;">char</span> *path<span style="color: #66cc66;">&#41;</span> <br />');
document.write('<span style="color: #66cc66;">&#123;</span><br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>!path<span style="color: #66cc66;">&#41;</span> <span style="color: #b1b100;">return</span> <span style="color: #cc66cc;">0</span>; <span style="color: #808080; font-style: italic;">// watch it, it\'s a pointer</span><br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #993333;">char</span> tmp<span style="color: #66cc66;">&#91;</span><span style="color: #cc66cc;">1024</span><span style="color: #66cc66;">&#93;</span>;<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; strcpy<span style="color: #66cc66;">&#40;</span>tmp,path<span style="color: #66cc66;">&#41;</span>;<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #993333;">char</span> *p = strrchr<span style="color: #66cc66;">&#40;</span>tmp,<span style="color: #ff0000;">\'<span style="color: #000099; font-weight: bold;">\\</span>\'</span><span style="color: #66cc66;">&#41;</span>;<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>p!=<span style="color: #000000; font-weight: bold;">NULL</span><span style="color: #66cc66;">&#41;</span> <br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; *p=<span style="color: #cc66cc;">0</span>;<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>strlen<span style="color: #66cc66;">&#40;</span>tmp<span style="color: #66cc66;">&#41;</span>&gt;<span style="color: #cc66cc;">3</span><span style="color: #66cc66;">&#41;</span> <br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span><br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; AP_RemovePath<span style="color: #66cc66;">&#40;</span>tmp<span style="color: #66cc66;">&#41;</span>;<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>_rmdir<span style="color: #66cc66;">&#40;</span>tmp<span style="color: #66cc66;">&#41;</span>!=<span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span> <br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">return</span> <span style="color: #000000; font-weight: bold;">true</span>;&nbsp; &nbsp; &nbsp; &nbsp; <br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">return</span> <span style="color: #000000; font-weight: bold;">true</span>;<br />');
document.write('<span style="color: #66cc66;">&#125;</span><br />');
document.write('&nbsp;</div>');
document.write('<br />&nbsp;<br /><div style="font-size: 12px">Brought to you by the community at <a href="http://www.bytemycode.com/snippets/snippet/257/1/" target="_blank">byteMyCode</a>.</div>');
