Recursive directory creationTrackbacks
Trackback specific URI for this entry
No Trackbacks
Comments
Display comments as
(Linear | Threaded)
And how does "mkdir -p" implement it? That's the root of the problem, as far as I understand Nico, and his solution is definitely cheaper than calling an external program.
bong
Its a C program not a shell script, so no mkdir -p. And I will not use system, exec, ... for such things
did you really test your code?
char *p; ... p = '/'; -> segfault you could also check opath[0] for a '/' so it won't try to access and create an empty path.
Yes off course I do.
The code seems to be fucked up because of the html formatting. Fuck, thanks! See http://nion.modprobe.de/tmp/mkdir.c for the difference.. It works! Fucking blog editor.
hi,
why don't you use strdup? why don't you use strsep + chdir? best regards
Thanks. I made a few edits to make it work in MSoft Visual C, and made it support wchar_t, and both forward and back slash:
void CreateDirectoryAnyDepth(const wchar_t *path) { wchar_t opath[MAX_PATH]; wchar_t *p; size_t len; wcsncpy_s(opath, path, sizeof(opath)); len = wcslen(opath); if(opath[len - 1] == L'/') opath[len - 1] = L'\0'; for(p = opath; *p; p++) { if(*p == L'/' || *p == L'\\') { *p = L'\0'; if(_waccess(opath, 0)) _wmkdir(opath); *p = L'\\'; } } if(_waccess(opath, 0)) _wmkdir(opath); }
you could just do
for i in 1 2 3 4 ; do mkdir $i ; cd $i ; done then you'd end up in /1/2/3/4 with all dirs created above... Add Comment
|
Calendar
QuicksearchSupportRecent Entries
CategoriesTag cloud23c3 acpi advertising annouce announce april argh art awards bash blogging bugs c cli code conferences config configuration data mining debconf debian dell dns documentation email errm? events exploit fail fail2ban filesharing films flame fun gcc google graphs grml gsm hacking hacks hardware heise images information installation internet irc knowledge libacpi links linux mobile phones network news newsbeuter omg open source opera passwords php power privacy programming qa random blurb rant release releases rss scripts security service setup shell sms software spam ssh stfl stuff terminal tests text mode tip tips tools troubleshooting unix user video vim.editing web web 2.0 websites wordpress wtf www youtube zsh
|