API 명령중에 DeleteFile 기능 사용과 관련해서 질문드립니다.

quarterhorse의 이미지

API를 독학으로 공부하고 있는 중입니다. 정말 초짜중의 초짜라 매우 쉬운데에서 부터 막히느라 막막한데요 ㅠ

API중에서 DeleteFile를 써보려고 하는데, 형식이 맞지 않는다고 오류를 뿜습니다.

만약 c:\test file\test file one.txt, c:\ test file\file\test file two.txt 두 파일을 지우려고 한다면,

어떻게 지정해야 제대로 동작하는지 궁금합니다.

일단 제가 연습해 보던 코드는 부분만 따와서 적어봅니다....

// *** BOOL DeleteFile(LPCTSTR lpFileName);형의 구조 사용 테스트
BOOL DeleteFile_test(LPCTSTR lpFileName);
//
 
LRESULT CALLBACK WndProc(HWND hWnd,UINT iMessage,WPARAM wParam,LPARAM lParam)
{
	switch (iMessage) {
 
 
        ... 생략
 
	}
	return(DefWindowProc(hWnd,iMessage,wParam,lParam));
}
 
BOOL DeleteFile_test(LPCTSTR lpFileName)
{
	char prog[]="c:\\test\\test.exe";
	DeleteFile(prog);
	return 0;
}
File attachments: 
첨부파일 크기
Image icon deletefile.png6.69 KB
익명 사용자의 이미지

아니면 TEXT매크로를 이용하면 형식오류는 해결될 것으로 보입니다.

vivisection의 이미지

BOOL DeleteFile_test(LPCTSTR lpFilename)
{
LPWSTR szSrcPath = _T("c:\\test.txt");
DeleteFile(szSrcPath);
return 0;
}

근데 인자는 왜받나요?
그리고 BOOL 형인데 왜 0을 리턴하나요?
shint의 이미지

1. 문자열 형변환이 궁금하다면. 네이버에서 이렇게 검색해 보세요
_T 매크로
C string _T
WideCharToMultiByte

http://kin.naver.com/qna/detail.nhn?d1id=1&dirId=1040101&docId=71509776&qb=QyBzdHJpbmcgX1Q=&enc=utf8&section=kin&rank=1&search_sort=0&spq=1
http://blog.naver.com/dkdaf?Redirect=Log&logNo=90156336556
http://rainbrolly.tistory.com/263
http://blog.naver.com/alonglog?Redirect=Log&logNo=130044427979
http://blog.naver.com/hello20?Redirect=Log&logNo=150017454132
http://blog.naver.com/acwboy?Redirect=Log&logNo=50143787793
http://cafe.naver.com/gisdev/767?social=1
http://binyjini.tistory.com/89
http://blog.naver.com/ysoftman?Redirect=Log&logNo=20065646151

//
C 관련 서적을 보시는게 좋습니다.

2. DeleteFile 는 msdn을 참고해보세요.
http://msdn.microsoft.com/ko-kr/library/windows/desktop/aa363915(v=vs.85).aspx
//0 이 아닐 경우. 성공이고. 리턴값이 0 이면. GetLastError로 확인해보라고 합니다.
fSuccess = DeleteFile(TEXT("datafile.txt"));
if (!fSuccess)
{
// Handle the error.
printf ("DeleteFile failed (%d)\n", GetLastError());
return (6);
}

3. 기능 구현하기
BOOL DeleteFile_test(LPCTSTR lpFileName)
{
int fSuccess = DeleteFile(lpFileName);
if (!fSuccess)
{
// Handle the error.
//printf ("DeleteFile failed (%d)\n", GetLastError());
return 0;
}
return 0;
}

//기능 사용하기
DeleteFile_test("datafile.txt");

----------------------------------------------------------------------------
젊음'은 모든것을 가능하게 만든다.

매일 1억명이 사용하는 프로그램을 함께 만들어보고 싶습니다.
정규 근로 시간을 지키는. 야근 없는 회사와 거래합니다.

각 분야별. 좋은 책'이나 사이트' 블로그' 링크 소개 받습니다. shintx@naver.com

quarterhorse의 이미지

제가 아직 많이 갈길이 멀다는 생각이 세삼 다시 생각되네요 ㅠㅠ

도움주신분들 정말 감사드리며 좋은 월요일 되셨으면합니다!

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.