c_cpp linux ln链接到win32 mklink链接

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了c_cpp linux ln链接到win32 mklink链接相关的知识,希望对你有一定的参考价值。

// lnToMklink.cpp : 콘솔 응용 프로그램에 대한 진입점을 정의합니다.
//

#include "stdafx.h"
#include <iostream>
#include <Windows.h>
#include <vector>
#include <fstream>
#include <string>

using namespace std;

std::wstring ReplaceString(std::wstring subject, const std::wstring& search,
	const std::wstring& replace) {
	size_t pos = 0;
	while ((pos = subject.find(search, pos)) != std::string::npos) {
		subject.replace(pos, search.length(), replace);
		pos += replace.length();
	}
	return subject;
}

vector<wstring> get_all_files_names_within_folder(wstring folder) 
{
	vector<wstring> names;
	wstring search_path = folder + L"/*.*";
	WIN32_FIND_DATA fd;

	HANDLE hFind = ::FindFirstFile(search_path.c_str(), &fd);
	if (hFind != INVALID_HANDLE_VALUE) {
		do {
			// read all (real) files in current folder
			// , delete '!' read other 2 default folder . and ..
			if (!(fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) {
				names.push_back(fd.cFileName);
			}
		} while (::FindNextFile(hFind, &fd));
		::FindClose(hFind);
	}
	return names;
}

int _tmain(int argc, _TCHAR* argv[])
{
	WIN32_FIND_DATA FindFileData;
	HANDLE hFind;

	if (argc != 2)
	{
		_tprintf(TEXT("Usage: %s [target_directory]\n"), argv[0]);
		return 1;
	}

	auto names = get_all_files_names_within_folder(argv[1]);
	auto loc = vector<wstring>();
	for (auto n : names) {
		_tprintf(TEXT("%s\n"), n.c_str());

		std::wstring filename = wstring(argv[1]) + L"/" + n;
		std::wifstream hFile(filename);

		std::vector<std::wstring> lines;
		std::wstring line;
		while (std::getline(hFile, line))
			lines.push_back(line);
		line = ReplaceString(line, L"/", L"\\");
		line = L"mklink / j " + n + L" " + wstring(argv[1]) + L"\\" + line;
		std::string str = "";
		str.assign(line.begin(), line.end());
		system(str.c_str());
	}

	return 0;
}

以上是关于c_cpp linux ln链接到win32 mklink链接的主要内容,如果未能解决你的问题,请参考以下文章

linux ln -s 用ln -s 链接 根目录到 /home/good怎么做啊。

linux每日命令:ln命令

Linux命令之软链接ln

Linux常用命令汇总--ln

Linux命令学习系列视频教程15-硬链接,链链接,ln命令

linux ln命令