This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
How to get the parent directory of the current folder in a C program?
I am using the C++ Windows API and I look for folders and directories given a specific directory path initially (i.e. C:\...\ProjectXX). I use in particular the functions FindFirstFile() and FindNextFile(). I want however sometimes to move "backwards" in a directory, namely to get the "parent" of the given directory (the folder which contains the directory given). In what way is this possible and under the use of what functions?
C++, unlike C, has a method for it: .remove_leaf(). But you're not using C++ functions, you're using WinAPI functions, so PathRemoveFileSpec() would be more fitting.
Related
This question already has answers here:
How to get current source path in C++ - Linux
(2 answers)
Closed 2 years ago.
I want get current file path,like in a.cpp,I can get
/home/workspace/src/a.cpp
How can I get this path?
You can use the standard macro __FILE__ to which expands to a string literal that contains the path of the current source file.
Starting from C++20, you can use default constructed std::source_location.
I couldn't comment due to the reputation requirement.
But you might find this useful, a way to retrieve directory on Linux & Windows.
How do I get the directory that a program is running from?
Hope this help!
This question already has answers here:
How can I get the list of files in a directory using C or C++?
(33 answers)
Closed 9 years ago.
I am a newbie so please don't be harsh on me for asking simple questions. my main question is how can I read from several files located in a directory sequently using a loop in c++ and perform some actions on them?
My code is like this:
string corpus = "corpus.txt";
myfile.open(corpus);
if (myfile.is_open())
while (!myfile.eof())
{
//Do something
}//end of while
MergeFiles(corpus,count);`
How can I do this actions on a set of files instead of just one.
Looks like you could do one of the following:
use windows APIs
use third party code
It looks like the simplest way is using diren.h. Look for at the sample code here:
How can I get the list of files in a directory using C or C++?
you can use the boost libraries, more specific - the filesystem library. This is more powerful but complicated solution, requires you to use iterators and higher programming methods.
using the windows API is not recommended because it requires dipper understanding of windows, and won't result a portable code. If you want to use it, there is an example in MSDN.
This question already has answers here:
Is there a command like "watch" or "inotifywait" on the Mac?
(16 answers)
Closed 9 years ago.
i require a callback within my code (in C++) which fires every time a particular file is modified (after a save), i am using a Mac however not Xcode, i am building my code using g++, documentation for this seems to be very limited. Does anyone have any example code which performs this functionality? Or can point me in the right direction as to where to look?
On Linux you would use ionotify, but OSX has FSEvents. It seems it will only notify you about changes to directories, it's up to you to then see if the event was about your file or not. There's a C API. This question has some examples.
This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
How to copy text file in C or C++?
I need a code which specifically look up a directory and find a pre-specified file name then copy it to another folder. It sounds easy but couldnt do it. Can anbody help me?
thanks
Some functions you may find useful from WINAPI:
FindFirstFile()
FindNextFile()
CopyFile()
boost has a filesystem library which has a copy_file function.
Last time I checked, C++ doesn't offer a file copy function. You need to open the file, read in its data into a local buffer, then make a new file, and write the contents of the local buffer into the new file.
File IO Reference
This question already has answers here:
Closed 11 years ago.
Possible Duplicates:
How can I limit lua possibilities (calling OS functions, modules, etc.)
How can I create a secure Lua sandbox?
luaL_openlibs(m_pState);
I use this function to load all the libs.I would like to skip all the dangerous libs like IO but I just cant find any documentation on how to disable a lib.
How do I disable certain libs? Are there more dangerous libs that can gain the script access to the system?
Add a copy of linit.c to your project and remove any libraries that you deem dangerous. To remove individual functions, set them to nil. See also the source of the Lua demo.