Click here to Skip to main content
15,886,806 members
Please Sign up or sign in to vote.
1.50/5 (2 votes)
See more:
Hello Code project members. I'm new to C++ and I want to make a software that does these steps:

1- Makes Downloads Directory.
2- Downloads text file that has name of files.
3- Moves the text file to the "Downloads" folder.
4- Reads the files names from the text file then downloads them.

My code:
*I've been searching for codes to make new folders and moving files ..etc, and I came across of system commands that can be used.
C++
#include <tchar.h>
#include <iostream>
#include <urlmon.h>
#include <string>
#include "stdlib.h"
using namespace std;
#pragma comment(lib, "urlmon.lib")

int main()
{
	string Dlfold;
	cout << "Welcome to Latest Files downloader, this software will let you download the lastest Files added\nFirst I'll make download folder for you\n";
	std::string s1 = "mkdir \Downloads\ ";
	system(s1.c_str());
	cout << "\nDownloads folder created, now let me check the latest releases...\n";
	HRESULT hr = URLDownloadToFile(NULL, _T("http://example.com/latest.txt"), _T("Latest.txt"), 0, NULL);
	std::string s2 = "move latest.txt \Downloads";
	system(s2.c_str());
	return 0;
}


The Code above does the two first steps, the file "Latest.txt" will have information like img1.png or video.mp4 which represents the name of files inside the directory.

I want the program to replace the names of files here:
C++
ULL, _T("http://example.com/latest.txt")

*instead of "http://example.com/latest.txt" I want it automatically to change to "http://example.com/img1.png" and "http://example.com/vid1.mp4" just like the name of files that written in the text file.

your help will be appreciated!!
*I'm using windows by the way.
Posted
Comments
Andreas Gieriet 10-Oct-14 8:51am    
Why re-inventing the wheel? Why not using wget?
Andi

1 solution

At first you should learn the basics in string operations. You can append, delete and replace in strings.

And then read and download the fine article about FileDownload.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900