Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed last month.
Improve this question
Can't get Recycle Bin path using SHGetKnownFolderPath. Hard coding C:\\$Recycle.Bin is an option which I want to avoid. Is there a way around this issue?
static std::string GetKnownWindowsFolder(REFKNOWNFOLDERID folderId, const char* errorMsg) {
LPWSTR wszPath = NULL;
HRESULT hr;
hr = SHGetKnownFolderPath(folderId, KF_FLAG_CREATE, NULL, &wszPath);
FreeCoTaskMemory scopeBoundMemory(wszPath);
if (!SUCCEEDED(hr)) {
throw std::runtime_error(errorMsg);
}
return sago::internal::win32_utf16_to_utf8(wszPath);
}
Thank You!
Get the folder path of Recycle Bin
The Recycle Bin is a virtual folder (like Control Panel and My Computer), it does not have a traditional path.
These virtual folders can be represented by an ITEMIDLIST. Call SHGetKnownFolderIDList() to retrieve it. See Introduction to the Shell Namespace for more information about the Shell Namespace and ItemIDLists.
That being said, there is a hidden Recycle Bin folder on each local drive, and the virtual folder displays a merged view of all of them. You can check if a folder is the Recycle Bin folder.
Related
This question already has answers here:
How do I query "Size on disk" file information?
(5 answers)
Closed 2 months ago.
I have a question on window folder property. When I'm checking property it's shows two size that is size and disk on size. So whenever I'm using qfileinfo it's show only size of folder. But i need "Size on disk". So what's is the method to get size on disk. And please explain that why is happening.
Help me for this.
Thanks in advance.
I want to check size on disk by qt C++ language
I doubt QT had a direct function to achieve the size on disk.
May be you can try like something below using windows API (as you mentioned windows).
Include fileapi.h, also below code not tested. Ensure compiled.
#include <Fileapi.h>
//GET THE FULL FILE NAME
QString filePath = qFileInfo->filePath();
//CONVERT THE FILE NAME TO LPCWSTR
LPCWSTR lpcwstrFilePath = (const wchar_t*) filePath.utf16();
//GET THE SIZE ON DISK
unsigned _int64 sizeOnDisk = GetCompressedFileSizeW(lpcwstrFilePath);
https://learn.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-getcompressedfilesizew
I am writing a Windows application, which collects (possibly hundreds of) names of files, all of which live in subfolders of one particular folder (which the user can select). The list is just a subset of all the files in the folders.
I do not want to implement a user-interface that offers all kinds of sorting and selection possibilities because Windows Explorer is always much better in this regard.
Is it there an API that allows me to launch Windows Explorer from my application such that it displays my list of files as if it were the result of a search operation?
The Explorer saved search format (.search-ms) is documented on MSDN. The only downside is that it will perform the actual search when you open it, it does not contain a list of paths of files found.
If this is unacceptable then you will have to get your hands dirty deep in IShellFolder and friends.
If hosting your own window is acceptable then IExplorerBrowser will get you 99% of the way there. Call IExplorerBrowser::FillFromObject to fill the view with a custom list of files or manipulate the view directly. Example code here.
If you must display the list in Explorer then I think you will have to bite the bullet and implement a namespace extension.
You can use the SHOpenFolderAndSelectItems function to open one particular folder.
LPCWSTR pszPathToOpen = L"C:\\Users\\strives";
PIDLIST_ABSOLUTE pidl;
if (SUCCEEDED(SHParseDisplayName(pszPathToOpen, 0, &pidl, 0, 0)))
{
// we don't want to actually select anything in the folder, so we pass an empty
// PIDL in the array. if you want to select one or more items in the opened
// folder you'd need to build the PIDL array appropriately
ITEMIDLIST idNull = { 0 };
LPCITEMIDLIST pidlNull[1] = { &idNull };
SHOpenFolderAndSelectItems(pidl, 1, pidlNull, 0);
ILFree(pidl);
}
Alternatively, you can call ShellExecute on the folder directly to run its default action (which is normally to open in a browser window):
ShellExecute(NULL, NULL, "C:\\Users\\strives", NULL, NULL, SW_SHOWNORMAL);
I have an Angular 4 app that allows a user to select multiple files for upload. When more than 20 files are selected, the document name turns blank (see screenshot) when you select less than 20, highlighted section looks fine and is populated.
My first thought is it's the file names. The file names appear to be UUID and after a certain length they no longer appear, but I'm at a loss on where to start with this. Then I thought it could be the file size, but the size of the files are negligible. (you can see the sizes in the screen shot. It would be nice to tell the customer what's causing the issue to give them a little guidance.
I did confirm all files are indeed in the same folder.
Anyone experience this issue? Any ideas what's causing this and what the fix may be?
Make sure that in the config is no or a high file count limit.
For example, "angular4-files-upload" you can create a file limit in the components.ts file as seen below:
import {
Ng4FilesService,
Ng4FilesConfig,
} from './ng4-files';
...
constructor(
private ng4FilesService: Ng4FilesService
) {}
private testConfig: Ng4FilesConfig = {
acceptExtensions: ['js', 'doc', 'mp4'],
maxFilesCount: 5,
maxFileSize: 5120000,
totalFilesSize: 10120000
};
ngOnInit() {
this.ng4FilesService.addConfig(this.testConfig);
}
I don't have a fix but maybe the cause.
I have an issue that results in the same error message (though not the disappearing file names) in my Java program.
From what I've found, the reason is the good old path length limit in Windows.
If the path of a selected file is too long, Windows will prefix the path with \\?\ (see https://learn.microsoft.com/en-us/windows/win32/fileio/naming-a-file#maximum-path-length-limitation).
Now, if only some of the selected files have a path that is over the limit, only some of the files will have that prefix. No longer do all files have the same parent path! Windows is apparently doing a rather simplistic check (like a string comparison) to see whether selected files are in the same directory.
This seems to be reproducible with any app that uses the native Open File dialog.
I want to figure out whether a given file is being copied or not. Initially I thought of doing fopen(_file) as fopen returns false while file is getting copied. But this idea fails when the file is opened in some applications(eg: when ppt is opened in MS powerpoint, fopen returns false). I'm in search of attributes of a file which uniquely identifies that the file is getting copied or not. I couldn't find such attributes even in boost::filesystem. Is this problem solvable using Boost lib? can someone help me in solving this issue?
boost filesystem fstream utility solved this issue
boost::filesystem::fstream fileStream(filePath, std::ios_base::in | std::ios_base::binary);
if(fileStream.is_open())
{
//not getting copied
}
else
{
//getting copied
}
I am busy writing an application that runs under windows
Where is the correct place to save temporary files ?
If you are using .NET, please use Path.GetTempPath(). This will guarantee that you use the temporary directory assigned to the user that runs your application, regardless of where it is stored.
If you browse the file system, you will notice that there are many "temp" directories:
~\Temp
~\Windows\Temp
~\Users\userName\AppData\Local\Temp
... and many more. Some of these paths are OS-dependent, and won't be present on certain windows flavors. So, save yourself some time and hassle, and let the .NET framework figure out where the "temp" path is located.
Use GetTempPath and and possibly GetTempFileName to determine where to put your temporary files. This is the most reliable, enduser-friendly, and future proof way to get a temporary location for files.
In the temp directory?
Use GetTempPath or in a batch file %TEMP%
C:\Temp is NOT a good choice.
If you are using .Net use code like this:
string baseFolder = System.Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
string cfgFolder = Path.Combine(baseFolder, "MyAppName");
try
{
if (!Directory.Exists(cfgFolder))
{
Directory.CreateDirectory(cfgFolder);
}
}
catch { } // If no access, not much we can do.
to get a place for medium-term storage of app data, or Path.GetTempPath() for transient storage of data.
Use the GetTempPath API, or the equivalent for your programming environment.
It depends on the language you are using:
string tempFolder = System.IO.Path.GetTempPath();
will return you the appropriate folder in C# for instance.
or, the environment variables TEMP or TMP if you must.
C:\Documents and Settings\username\Application Data\IsolatedStorage