-1

I'm working on a project in which I have to do some file handling.

If only someone could tell how to work with file system like moving, copying, deleting, renaming and checking for the existence of files in Windows.

Community
  • 1
  • 1
  • 1
    If ther is any problem with the Question pleas tell me last time my question was put on rest becuz of which i was unable to ask any question for morthan 4 days so pleas if u see any prolem pleas mp me or leav a comment – Zia-ur-Rehman Rehmani May 10 '17 at 18:46
  • 1
    You are need to show what you have tried. Not just ask for help. Google can answer your question as asked. See: http://stackoverflow.com/help/asking – Richard Critten May 10 '17 at 18:47
  • Sory sir i hev no idea how to work with file system in c++ im a newbie to c++ i did try to serch on web but all i find was to learn the bost library and that i cant do becuz it will put mee way behind the dead line – Zia-ur-Rehman Rehmani May 10 '17 at 18:50
  • MSDN file handling functions: https://msdn.microsoft.com/en-us/library/windows/desktop/aa364232(v=vs.85).aspx C++17 filesystem: http://en.cppreference.com/w/cpp/filesystem – Richard Critten May 10 '17 at 18:51

1 Answers1

0

Check file management functions section on msdn.

For example, to copy a file with WinAPI you can use CopyFile:

#include <windows.h>
#include <iostream>

int main()
{
    BOOL ret = CopyFile(TEXT("test.txt"), TEXT("test-copy.txt"), TRUE);
    if (ret)
        std::cout << "CopyFile failed. GetLastError:" << GetLastError() << std::endl;
}

If your compiler supports you may as well use std::filesystem which is portable (e.g. that code should work equally well on windows and linux):

#include <filesystem>

int main()
{
    std::filesystem::copy("test.txt", "test-copy.txt");
}

There is also boost::filesystem that heavily influenced std::filesystem.

Pavel P
  • 15,789
  • 11
  • 79
  • 128