I'm working with visual studio 2012.
In status quo, in MFC form there is a input box and it takes entire directory path of mp3 file which will be used in MFC. However, the files should be clicked and selected to be executed and this is very laborious job.
Currently, the file path is saved in this->tb_filePath->Text form in MFC, and after the private: System::Void Run_Click(System::Object^ sender, System::EventArgs^ e) is clicked, a function gets the file path saved above and executes.
Since all the mp3 files are saved in specific directory, I tried to make this process automatically. Also in directory,
xxxxx.mp3
aaxxx.txt
xxxx1.mp3
aaxx1.txt
there are mp3 formats and txt formats, I have to distinguish those files also. txt is not allowed as an input. But I'm not familiar with window-MFC form right now, so I'm not sure how can I start with this.
First, how can I automatically access to the directory and read the files that will be used in the .exe program. And how can I know that I have found all the files?
Second is it possible to select next files in folder when I press the certain button of the MFC?
Overall, I am not sure how can I search through all the .mp3 files in certain directory without selecting it one by one.
This was solved. It was just a problem dealing with directory and file relations. sorry for the poor questioning.
Related
I am working on a project where I have to read in serveral pre-existing CSV (dog.csv, horse.csv, etc.). I want to know how would I add these file into my project so that I may test to see if my print functions work (the code is written in c++). Would I have to copy and paste the files into the debugging folder or would I place it under the test folder of the project?
You can include the files in your project in whatever (sub)folder you wish by using Right click -> Add -> Existing Item. Then, right-click on each file and choose Properties. Set up "Copy to output directory" to "Copy if newer".
Then after build, your files will be copied into the bin/debug folder.
To read the file, you can just use:
System.IO.File.ReadAllText("dog.csv");
Another possible way is to add a file within project, right click and select properties, and then in Copy to Output Directory, select Copy always. This way, csv file will be automatically copied in your debug and release packages too.
string executableLocation = Path.GetDirectoryName(
Assembly.GetExecutingAssembly().Location);
string csvLocation= Path.Combine(executableLocation, "file.csv");
Above code will read file location from bin directory where your csv file will be stored.
This link should help guide you how to add CSV files to a project.
If you wanted to do a down and dirty way you could just save the CSV's somewhere on your local machine, and then hard code the file path to that location.
Example:
c:\test\Dog.csv and then set that as a variable for whenever you need to read in the csv file.
I am working on a project which requires me to open an HTML file and use its contents. I added it to Resource files but when I try to open it lie this:
std::ifstream templateFile;
templateFile.open("filename.html", std::ifstream::in);
The operation fails. I checked it by using templateFile.fail().
The above operation works when I provide the full path. The file lies in the project folder along with other files. I tried setting build action to content but still it doesnt work. Please Help.
Output directory, where your executable is compiled and put into differs from the source directory, where you create all your .cpp/.hpp files (I assume there is filename.html file). Local path filename.html is supposed to be local for your executable file, not the source file.
Read more about changing the output directory here: https://msdn.microsoft.com/en-us/library/ms165410.aspx
Under Configuration Properties / Debugging, see what your Working Directory is using the macros dialog box. Move your file into this folder.
Click the button shown in the figure. There, click either Edit or Browse. Browse will take you to the working directory. Edit will expose the link to open the macros box
I'm using Wischik's example code for creating AVI files, however after I run the code and it exits successfully no AVI file is created. I looked through the code and cannot find where it writes/saves/creates an AVI file on your computer. Does anyone know where the code saves AVI file or if it doesn't, a way to make it save the AVI file created to your computer? Thanks
link to source code here
Wischik source code
You should find test.avi in the project directory. Since you know it's name, you could also use Windows explorer to search for it.
To examine further, (assuming you are using VC++), goto
Tools > Options > Projects and Solutions > VC++ Directories,
and Show Directories for Include files.
That will tell you where the headers are.
Alternatively, set a break point at the line where AVIFileOpen is called, and follow the execution path to see what it does.
I'm making an application to backup the opened folders.
The problem is that if in that folders are some special folders (ex: "Desktop", "Computer", "Libraries\Documents", ...) they will not open.
I know that there are constants for those objects, but I don't know which folders will be opened so making a dictionary with all SpecialNames => SpecialConstant is not a good solution for me.
So the question is:
Is there any WinApi function to retrieve the full path from a short name of a special folder?
P.S. Tried both ShellExecute("open", "Path") and ShellExecute("open", "explorer.exe", "Path")
If you paste the names in the explorer they work, but opening them from C++ doesn't work
Thanks
Libraries are stored in the users %appdata%\Roaming\Microsoft\Windows\Libraries directory as XML files with the names <libraryname>.library-ms (e.g. Pictures.library-ms.) Opening one of these files with ShellExecute opens an Explorer window and shows the library.
I need to select the path directory of my "files.dat" at runtime.
My Visual Studio project create a .dll (that is a Nutech plugin) and in the code it is just implemented a load functions of this files. So I need that the user can choose the directory of files to load to the process.
Your function must receive a name of an input file as a parameter and do exactly one thing: load data from the file. Everything else (like showing a dialog) is responsibility of the user code.