api一日一练 第11天 CreateDirectory RemoveDirectory
前几天给初学者一点压力-----一些思考题大家居然没去做------
今天就出些简单点的吧------
创建一个文件夹和删除一个文件夹
需要实现的步骤--判断文件夹不存在---》然后创建文件夹
判断文件夹存在-----》删除文件夹
BOOL CreateDirectory
(
LPCTSTR lpPathName, // 指向的是要创建的文件夹路径
LPSECURITY_ATTRIBUTES lpSecurityAttributes// 指针安全描述符
);
BOOL RemoveDirectory
(
LPCTSTR lpPathName //指向一个要删除的文件夹路径
);
**** Hidden Message *****
思考题:获取当前目录路径,然后改变当前目录路径
初学者, 思考题
来看看 努力努力努力,谢谢了 发帖发帖发帖 本帖最后由 君子坦蛋蛋 于 2012-12-27 17:17 编辑
课堂作业:文件的创建和删除
不存在:
已存在:
代码:
#include "stdafx.h"
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
// TODO: Place code here.
if( CreateDirectory("C:\\Documents and Settings\\Owner\\桌面\\嘿嘿交作业", NULL) == 1 )
{
MessageBox(NULL, "创建成功!", "温馨提示", MB_OK);
}
else
{
RemoveDirectory("C:\\Documents and Settings\\Owner\\桌面\\嘿嘿交作业");
MessageBox(NULL, "桌面存在该文件夹,已成功删除!", "温馨提示", MB_OK);
}
return 0;
}
课后作业:获取当前路径并改变路径
获取当前路径:
改变路径:
代码:
#include "stdafx.h"
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
// TODO: Place code here.
char fPath;
char nPath = "C:\\Documents and Settings\\Owner\\桌面\\嘿嘿交作业";
char mPath = "1.exe";
GetModuleFileName(NULL, fPath, MAX_PATH);
int i = MessageBox(NULL, fPath, "当前路径", MB_OK);
if( i = IDOK )
{
strcat(nPath, "\\1.exe");
CopyFile(fPath, nPath, true);
MessageBox(NULL, nPath, "改变路径", MB_OK);
}
return 0;
}
支持小七作业还是要交滴!
attachimg]5942[
// 创建文件与删除.cpp : Defines the entry point for the application.
//
#include "stdafx.h"
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
// TODO: Place code here.
//API一天一连第十天!
//www.xiaoqi.com love xiaoqi !
TCHAR path;
strcpy(path,"c:\\lovexq");
int ret =
MessageBox(NULL,TEXT("文件夹不存在! 是否要创建?"),TEXT("提示!"),
MB_ICONQUESTION | MB_YESNO);
if ( IDYES == ret )
{
CreateDirectory(path,NULL);
MessageBox(NULL,TEXT("创建完毕!"),TEXT("XIAOQI"),MB_OK);
}
ret =
MessageBox(NULL,TEXT("是否要删除目录?"),TEXT("提示!"),
MB_ICONQUESTION | MB_YESNO);
if ( IDYES ==ret )
{
RemoveDirectory(path);
MessageBox(NULL,TEXT("删除完毕!"),TEXT("XIAOQI"),MB_OK);
}
// GetModuleFileName()
return 0;
}
家庭作业:
// 获取路径并且改变.cpp : Defines the entry point for the application.
//
#include "stdafx.h"
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
// TODO: Place code here.
TCHAR path;
TCHAR mbpath;
GetModuleFileName(NULL,path,256);
int ret =
MessageBox(NULL,path,TEXT("提示!"),
MB_ICONQUESTION | MB_YESNO);
if ( IDYES == ret )
{
strcpy(mbpath,"c:\\lovexq\\love.exe");
MoveFileEx(path,mbpath,
MOVEFILE_REPLACE_EXISTING | MOVEFILE_COPY_ALLOWED );
MessageBox(NULL,mbpath,TEXT("提示!"),MB_OK);
}
return 0;
}
看看噢 来看看