Dave's Brain

Browse - Programming Tips - How can I programatically make a symbolic link?

Date: 2015apr3
Language: C/C++
Platform: win32

Q.  How can I programatically make a symbolic link?


BOOL IsDir(LPCWSTR szDir) { DWORD dwAttrib; if ((dwAttrib = GetFileAttributes(szDir)) == 0xFFFFFFFF) return FALSE; return (dwAttrib & FILE_ATTRIBUTE_DIRECTORY); } BOOL MakeSymLink(szSrc, szTarget) { DWORD flags = IsDir(szTarget) ? SYMBOLIC_LINK_FLAG_DIRECTORY : SYMBOLIC_LINK_FLAG_FILE; if (!CreateSymbolicLink(szSrc, szTarget, flags)) { DWORD dwError = GetLastError(); fprintf(stderr, "Could not make symbolic link because %d\n", dwError); return FALSE; } return TRUE; }

Add a comment

Sign in to add a comment
Copyright © 2008-2018, dave - Code samples on Dave's Brain is licensed under the Creative Commons Attribution 2.5 License. However other material, including English text has all rights reserved.