1

I am completing a project to create dummy file systems for backup testing and need to develop a method of creating a Hardlinks and Softlinks within the structures.

The CreateHardLink and CreateSymbolicLink functions in windows.h receive file location and names based upon the current working directory.

The source code now changes directory, but those two functions do not successfully execute.

 wstring hltarg;
 hltarg = L"sym";
 hltarg += ExistingFileName;
 CreateHardLinkW(hltarg.c_str(), ExistingFileName.c_str(), NULL)

where hltarg concatenates the existing file name to the end of sym.

Because I moved my working directory to my target directory, neither of these strings contains a full path, but rather just the target file names.

Any advice on a different route to take rather than changing current directory?

The application will need to be portable so no hard references to file paths can be made, although desired file paths will be provided.

jscott
  • 397
  • 2
  • 5
  • 18
  • 3
    These functions return a BOOL, but also set the last error. If unsuccessful, check with `GetLastError`. – 0xC0000022L Jun 02 '11 at 21:11
  • 2
    As an aside, I find it is more useful to work with full paths as the current directory can be changed out from under you without warning. – Luke Jun 02 '11 at 21:26
  • Everyones feedback here helped me immensely. Just wanted to verify, does `CreateHardLink` work even on limited user accounts? Like non-admin? – Noitidart Mar 29 '15 at 19:58

0 Answers0