3 Replies - 682 Views - Last Post: 28 October 2013 - 11:52 AM Rate Topic: -----

#1 mkash  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 27-October 13

c++ visual studio deleting and copying folder code problem help

Posted 27 October 2013 - 10:11 AM

can any1 help me with my code because i cant delete and copy a folder but i can copy and delete other file extensions. it would be a great help if you can help me with this cause im new in c++...thank you and godbless.

code for the delete:

#include "stdafx.h"
#include <windows.h>
#include <conio.h>



int _tmain(int argc, _TCHAR* argv[])
{
	
	
	CopyFile(argv[1],argv[2],TRUE);


	getch();
	return 0;

}





code for the copy:

#include "stdafx.h"
#include <windows.h>
#include <conio.h>



int _tmain(int argc, _TCHAR* argv[])
{
	
	DeleteFile(argv[1]);
	


	getch();
	return 0;

}




Is This A Good Question/Topic? 0
  • +

Replies To: c++ visual studio deleting and copying folder code problem help

#2 ccubed  Icon User is offline

  • It's That Guy
  • member icon

Reputation: 160
  • View blog
  • Posts: 1,403
  • Joined: 13-June 08

Re: c++ visual studio deleting and copying folder code problem help

Posted 27 October 2013 - 12:30 PM

DeleteFile is not for deleting a folder, it's for deleting a single file.

If you want to remove an empty directory then you want: RemoveDirectory

If you want to remove a folder and empty it of all files then you want: SHFileOperation (In Vista+ this is now IFileOperation)

If you want to copy a folder then you want: SHFileOperation (IFileOperation)

If you want to copy a file then you want: CopyFile

If you want to copy a folder and all contents you want: SHFileOperation (IFileOperation)

If you want to move a file: MoveFile

Basically, Copying, Moving and Removing Directories with contents is done with SHFileOperation (IFileOperation).

Edit: As an addendum, you can actually do all that you want just using SHFileOperation or IFileOperation.

This post has been edited by ccubed: 27 October 2013 - 01:04 PM

Was This Post Helpful? 0
  • +
  • -

#3 mkash  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 27-October 13

Re: c++ visual studio deleting and copying folder code problem help

Posted 27 October 2013 - 07:03 PM

@ccubed how do i put the IFileOperation in my code? :helpsmilie:
Was This Post Helpful? 0
  • +
  • -

#4 Salem_c  Icon User is offline

  • void main'ers are DOOMED
  • member icon

Reputation: 1653
  • View blog
  • Posts: 3,129
  • Joined: 30-May 10

Re: c++ visual studio deleting and copying folder code problem help

Posted 28 October 2013 - 11:52 AM

cross-posted and answered -> http://forums.devshe...elp-953617.html
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1