【问题标题】:How to give a file path instead of file name c++?如何给出文件路径而不是文件名 c++?
【发布时间】:2020-11-27 09:31:39
【问题描述】:

此代码部分来自一个简单的 md5 哈希生成器。但这里我只能给出一个文件名来生成 md5。

LPCWSTR NameOfTheFile = L"Test.txt"; //Name of the file that user is scanning

但是我想在这里给出一个文件路径而不是文件名..有什么办法吗?

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

#define BUFSIZE 1024
#define MD5LEN  16


using namespace std;


DWORD main()
{

    MaximizeOutputWindow();

    DWORD cryptStatus = 0;

    BOOL hashResult = FALSE;

    BYTE fileSizeToHash[BUFSIZE];

    HCRYPTPROV cryptProv = 0;

    HCRYPTHASH hash = 0;

    HANDLE file = 0;

    DWORD hashNumbCount = 0;

    DWORD hashRead = 0;

    BYTE getHashValue[MD5LEN];

    CHAR numberConvert[] = "0123456789abcdef"; //hex decimal conversion

    LPCWSTR NameOfTheFile = L"Test.txt"; //Name of the file that user is scanning


    // Logic to check usage goes here.
    file = CreateFile(NameOfTheFile, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_FLAG_SEQUENTIAL_SCAN, NULL);

【问题讨论】:

  • 您是否尝试使用文件的绝对路径而不是相对路径?当你尝试这样做时发生了什么?
  • here i can only give a file name 不,CreateFile 通常采用完整路径,单独的文件名仅被解释为文件位于当前目录中的相对路径。

标签: c++ md5


【解决方案1】:

您可以使用带有CreateFile 的文件路径。尝试类似NameOfTheFile = L"C:\\Text.txt";

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-05-14
    • 1970-01-01
    • 2018-08-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-04-08
    相关资源
    最近更新 更多