如何用c语言实现生成文件夹?

Samuelsun 2006-06-08 11:21:02
c语言提供了用于建立文件的函数了嘛?
谢谢!
...全文
688 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
itisyu 2006-06-12
  • 打赏
  • 举报
回复
用mkdir(char *name)生成相对的文件夹后,可以用chdir(char *name)进入这个文件夹,用getcwd(char *othername,sizeof(char *othername))得到绝对路径,也许在你删除文件夹时会用到.
在用rmdir(char *name)删除文件夹时要保证这个文件夹是空的.
jixingzhong 2006-06-08
  • 打赏
  • 举报
回复
#include <stdlib.h>

system("md xxx"); //建立文件夹 xxx (可以使用绝对路径控制文件夹的位置)
51365133 2006-06-08
  • 打赏
  • 举报
回复
_mkdir, _wmkdir
Create a new directory.

int _mkdir( const char *dirname );

int _wmkdir( const wchar_t *dirname );

Routine Required Header Compatibility
_mkdir <direct.h> Win 95, Win NT
_wmkdir <direct.h> or <wchar.h> Win NT


For additional compatibility information, see Compatibility in the Introduction.

Libraries

LIBC.LIB Single thread static library, retail version
LIBCMT.LIB Multithread static library, retail version
MSVCRT.LIB Import library for MSVCRT.DLL, retail version


Return Value

Each of these functions returns the value 0 if the new directory was created. On an error the function returns –1 and sets errno as follows:

EEXIST

Directory was not created because dirname is the name of an existing file, directory, or device

ENOENT

Path was not found

Parameter

dirname

Path for new directory

Remarks

The _mkdir function creates a new directory with the specified dirname. _mkdir can create only one new directory per call, so only the last component of dirname can name a new directory. _mkdir does not translate path delimiters. In Windows NT, both the backslash ( \) and the forward slash (/ ) are valid path delimiters in character strings in run-time routines.

_wmkdir is a wide-character version of _mkdir; the dirname argument to _wmkdir is a wide-character string. _wmkdir and _mkdir behave identically otherwise.

Generic-Text Routine Mappings

TCHAR.H Routine _UNICODE & _MBCS Not Defined _MBCS Defined _UNICODE Defined
_tmkdir _mkdir _mkdir _wmkdir


Example

/* MAKEDIR.C */

#include <direct.h>
#include <stdlib.h>
#include <stdio.h>

void main( void )
{
if( _mkdir( "\\testtmp" ) == 0 )
{
printf( "Directory '\\testtmp' was successfully created\n" );
system( "dir \\testtmp" );
if( _rmdir( "\\testtmp" ) == 0 )
printf( "Directory '\\testtmp' was successfully removed\n" );
else
printf( "Problem removing directory '\\testtmp'\n" );
}
else
printf( "Problem creating directory '\\testtmp'\n" );
}


Output

Directory '\testtmp' was successfully created
Volume in drive C is CDRIVE
Volume Serial Number is 0E17-1702

Directory of C:\testtmp

05/03/94 12:30p <DIR> .
05/03/94 12:30p <DIR> ..
2 File(s) 0 bytes
17,358,848 bytes free
Directory '\testtmp' was successfully removed

happytang 2006-06-08
  • 打赏
  • 举报
回复

#include <stdio.h>
#include <conio.h>
#include <process.h>
#include <dir.h>

int main(void)
{
int status;

clrscr();
status = mkdir("asdfjklm"); //建立
(!status) ? (printf("Directory created\n")) :
(printf("Unable to create directory\n"));

getch();
system("dir");
getch();

status = rmdir("asdfjklm"); //删除
(!status) ? (printf("Directory deleted\n")) :
(perror("Unable to delete directory"));

return 0;
}

可以自己定义路径system("dir");
tom955 2006-06-08
  • 打赏
  • 举报
回复
#include <stdio.h>
#include <direct.h>

main()
{
mkdir("c:\\我是天才");

return 0;
}
rexking0 2006-06-08
  • 打赏
  • 举报
回复
#include <fcntl.h>
#inclue <unistd.h>
int mkdir(const char *dirname, mode_t mode);
int rmdir(char * pathname);

69,382

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧