_makepath_s/_splitpath_s
从组件创建路径名/从路径拆分目录
char path_buffer[_MAX_PATH];
char drive[_MAX_DRIVE];
char dir[_MAX_DIR];
char fname[_MAX_FNAME];
char ext[_MAX_EXT];
errno_t err;
err = _makepath_s(path_buffer, _MAX_PATH, "c", "\\sample\\crt\\",
"crt_makepath_s", "c");
if (err != 0)
{
printf("Error creating path. Error code %d.\n", err);
exit(1);
}
printf("Path created with _makepath_s: %s\n\n", path_buffer);
err = _splitpath_s(path_buffer, drive, _MAX_DRIVE, dir, _MAX_DIR, fname,
_MAX_FNAME, ext, _MAX_EXT);
if (err != 0)
{
printf("Error splitting the path. Error code %d.\n", err);
exit(1);
}
printf("Path extracted with _splitpath_s:\n");
printf(" Drive: %s\n", drive);
printf(" Dir: %s\n", dir);
printf(" Filename: %s\n", fname);
printf(" Ext: %s\n", ext);
_getcwd ,?_wgetcwd
获取当前工作目录。
char *_getcwd(
char *buffer,
int maxlen
);
wchar_t *_wgetcwd(
wchar_t *buffer,
int maxlen
);
参数
buffer 路径的存储位置。
maxlen 路径的最大长度(以字符为单位):?char ?的?_getcwd ?和?wchar_t ?的?_wgetcwd 。
返回值
返回指向?buffer 的指针。?NULL ?返回值指示错误,并将?errno ?设置为?ENOMEM ,指示内存不足,无法分配?maxlen ?个字节(当将?NULL ?参数给定为?buffer 时),或设置为?ERANGE ,指示该路径长于?maxlen ?个字符。 如果?maxlen ?小于或等于零,则此函数调用无效的参数处理程序,如?Parameter Validation。
#include <direct.h> // _getcwd
#include <stdlib.h> // free, perror
#include <stdio.h> // printf
#include <string.h> // strlen
int main( void )
{
char* buffer;
// Get the current working directory:
if ( (buffer = _getcwd( NULL, 0 )) == NULL )
perror( "_getcwd error" );
else
{
printf( "%s \nLength: %zu\n", buffer, strlen(buffer) );
free(buffer);
}
}
system 命令?
system("md ..\\x64\\Release\\file");// 指定目录新建文件夹
system("del ..\\x64\\Release\\file"); // 删除该文件夹下的所有文件
|