Trying to help out this person at this other thread at link below and figured it would be an easy quick program to code up. Coded up and compiled fine, but oddly I am able to create .lnk shortcuts but the shortcuts dont bring you to the destination. Nothing happens when clicking on the shortcut.
On my system I created structure similar to this other person who is looking for help with:
C:\MyProjects\
I then created a Project folder of Project123
so C:\MyProjects\Project123 exists
I then had added FolderA and FolderC subdirectories at Project123
When running my program below and telling it Project123 it runs to the path of C:\MyProjects\Project123\FolderC\ and creates a shortcut pathed to C:\MyProjects\Project123\FolderA\ named Goto_FolderA.lnk the program writes to this correctly however the .lnk doesnt work as a .lnk shortcut even though Windows 7 64-bit recognizes it as a shortcut.
Additionally I am unable to look into this .lnk to see whats in it as you can do with shortcuts generated by windows, so i flipped the extension to .txt instead of .lnk to verify that the correct path info was being written and it is .... what I noticed also is that the shortcut I generate is 35 bytes and ones created by Windows are larger such as below:
C:\2017\programming>dir
Volume in drive C has no label.
Volume Serial Number is 125F-376A
Directory of C:\2017\programming
04/26/2017 11:15 PM <DIR> .
04/26/2017 11:15 PM <DIR> ..
04/26/2017 11:14 PM 1,326 Goto_FolderA - Shortcut.lnk
04/26/2017 09:07 PM 317 Project1.cpp
04/26/2017 09:07 PM 475,586 Project1.exe
04/26/2017 11:14 PM 460 Project2.cpp
04/26/2017 11:14 PM 500,780 Project2.exe
04/26/2017 10:59 PM 456 Project2a.txt
04/26/2017 09:07 PM 35 test.txt
7 File(s) 978,960 bytes
2 Dir(s) 5,009,920,000 bytes free
C:\2017\programming>cd\.
C:\>cd myprojects
C:\MyProjects>cd project123
C:\MyProjects\Project123>cd folderC
C:\MyProjects\Project123\FolderC>dir
Volume in drive C has no label.
Volume Serial Number is 125F-376A
Directory of C:\MyProjects\Project123\FolderC
04/26/2017 11:07 PM <DIR> .
04/26/2017 11:07 PM <DIR> ..
04/26/2017 11:07 PM 35 Goto_FolderA.lnk
04/26/2017 11:07 PM 35 Goto_FolderA.txt
2 File(s) 70 bytes
2 Dir(s) 5,009,920,000 bytes free
C:\MyProjects\Project123\FolderC>
So what magic does Windows add to this file to bloat it to 1,326 bytes from 35 bytes and make it an active working shortcut? ... yet opening both files shows the same path of C:\MyProjects\Project123\FolderA\ and nothing else?Here is the program I slapped together quickly that allows creation of Project_Name pathed shortcuts to be planted into FolderC for a quick hop to FolderA for same project... but the .lnk shortcuts are non functional and much smaller than shortcuts created under windows.
#include <iostream>
#include <string>
#include <fstream>
int main() {
std::string Project_Name;
std::cout<<"Enter Project Name\n";
std::cin>>Project_Name;
std::string filepath = "C:\\MyProjects\\";
std::ofstream outfile;
outfile.open((filepath.append(Project_Name+"\\FolderC\\Goto_FolderA.lnk")).c_str(),std::ios_base::trunc);
outfile <<"C:\\MyProjects\\"<<Project_Name<<"\\FolderA\\\n";
outfile.close();
return 0;
}
Here is the link to the project that I was going to help out at, but found out that now I too need help with the fact that I guess I might not completely understand how shortcuts are generated in Windows. For years I always thought a path in a text file that is saved as a .lnk instead of .txt would function as a shortcut. Maybe years ago it was the case and Windows evolved to not allow this or there is more to it than a path contained in a file under a .lnk file extension.
http://www.computerhope.com/forum/index.php/topic,160548.0/topicseen.html