How to create executable shortcut using qt? - windows

I want to create short cut for my executable in windows startup menu. I can get the startup folder path and my executable full path but it seems I can use QFile::link() but I don't know how can create that in the startup folder?
QString starupFolder = QStandardPaths::writableLocation(QStandardPaths::ApplicationsLocation) + "/Startup";
QString appPath = qApp->applicationDirPath() + "/DataSync.exe";
Now I could possibly do this:
QFile file;
file.setFileName( appPath );
file.link("DataApp");
Maybe I am rusty today but how do I actually save/create the link like on file system and specially to startup menu in windows?

Related

shortcut in the windows starting menu - Matlab executable

I create an executable based on a gui with several functions and files, and if I open the executable in the installation folder or using the desktop shortcut everything works fine. If I open through the starting menu, the executable doesn't incorporate the images and doesn’t run. What I can do to prevent this issue? Is it possible to prevent the shortcut in the windows starting menu?
I found a solution here:
You can use the following function to get the folder of the executed exe file:
function currentDir = getcurrentdir()
if isdeployed % Stand-alone mode.
[status, result] = system('path');
currentDir = char(regexpi(result, 'Path=(.*?);', 'tokens', 'once'));
else % MATLAB mode.
currentDir = pwd;
end
Call the function and use cd in the GUI opening function:
currentDir = getcurrentdir();
cd(currentDir);
I created a guide testing application, and used deploytool for compiling and packaging for external deployment.
For testing, I added a text label to the GUI (Tag name: text2).
In the GUI opening function I added the following code:
% --- Executes just before GuideApp is made visible.
function GuideApp_OpeningFcn(hObject, eventdata, handles, varargin)
handles.output = hObject;
handles.text2.String = 'Starting...';
pause(1);
currentDir = getcurrentdir();
%Set the label's text to display currentDir.
handles.text2.String = currentDir;
%Change directory to the directory of the exe file.
cd(currentDir);
%Create a file in the directory (just for testing):
f = fopen('currentDir.txt', 'w');fprintf(f, '%s\r\n', currentDir);fclose(f);
% Update handles structure
guidata(hObject, handles);
The above solution is working correctly:
The text of label displays the path of the exe file.
currentDir.txt file is created in the path of the exe file.

Python os.rename "\" and "/" cross-platform issue

I'm trying to make a cross-platform program that move a file to a folder inside the user home folder, like this:
os.rename(file_var, destination_folder)
but I can't make it work because I need to put the file name inside the destination var, and the problem is the Windows "\"
what are my options?
do this:
for example you want this path:
'+pathfile+'/output/log.txt'
instead of typing a string, join them like this:
os.path.join(pathfile,"output","log.txt")
NOTE:
according to this post / works both in windows and linux, i always use os.path.join()

Programmatically create shortcuts for folders in Windows

I have a folder A and a folder B. For each subfolder inside A I need to check if B contains a link to that subfolder. If not, I need to create it.
I'm currently creating the links using the code found on this page: Creating a file shortcut (.lnk)
My problem is that this code always creates a file shortcut, not a folder shortcut, so if I try to open the shortcut it does not open the corresponding folder. Anyone knows how to create folder shortcuts instead?
I'll answer my own question because I found lots of people asking this on the web and nobody providing an answer.
I found through trial and error that if you use the Path.GetFullPath method to calculate the value to assign to the TargetPath property, the output is in a format that's recognized as a folder path, so the system will automatically identify it as a folder shortcut and assign the corresponding icon.
FileSelectFolder, directory
if (directory != ""){
Loop, %directory%*.*, 1, 1
{
if (FileExist(A_LoopFileFullPath) = "D")
FileCreateDir, % A_Desktop "\myShortcuts" SubStr(A_LoopFileFullPath, StrLen(directory) + 1)
else
FileCreateShortcut, %A_LoopFileFullPath%, % A_Desktop "\myShortcuts" SubStr(A_LoopFileFullPath, StrLen(directory) + 1) A_LoopFileName ".lnk"
}
Run, % A_Desktop "\myShortcuts"
}
Esc::ExitApp

Retrieve StorageFile with the help of path from Local Folder

I am making Windows 8.1 Universal App and want to retrieve file,
(local -> folder -> sub Folder -> file) which is stored in Local Folder.
One way is open Local Folder, then open folder, then open sub folder, then file.
But If I know the path, can I simply open the file?
(Like in Windows Phone 8, store.OpenFile())
Is there an API which would return Storage File when passed path?
Example: GetStorageFile("local/folder/subFolder/file") ?
You can use StorageFile.GetFileFromApplicationUriAsync and pass in a URI such as ms-appdata:///local/folder/subfolder/file.txt. This is preferred over GetFileFromPathAsync (#Parad1s3's suggestion) since it is relative to your data folder and won't change if the location of the app changes (eg, on a phone the user can move to or from the SD card).
string path = ApplicationData.Current.LocalFolder + "\\" + "YourFolder" + "\\" + "YourSubfolder" + "\\yourfile.xml";
StorageFolder folder = ApplicationData.Current.LocalFolder;
StorageFile file = await folder.GetFileAsync(path);
Hope this helps.

Checking if a Folder/File is Hidden/System in Windows C/C++

I am writing a Cross platform application using C++/STL/Boost and I realized they do not provide a way to check if a folder or file is hidden or is a system file in Windows.
What's the simplest way to do this in C/C++ for Windows ?
Ideally I have a std::string with the path (either to a file or folder), and would return if it's hidden or is a system file. best if it works across all windows versions. I am using MinGW g++ to compile this as well.
GetFileAttributes will work for this.
It takes a path to either a file or a directory as a parameter and returns set of flags including FILE_ATTRIBUTE_HIDDEN and FILE_ATTRIBUTE_SYSTEM.
DWORD attributes = GetFileAttributes(path);
if (attributes & FILE_ATTRIBUTE_HIDDEN) ...
if (attributes & FILE_ATTRIBUTE_SYSTEM) ...

Resources