Search by size in directory then delete

Hello!

I need some help in code.

What I am trying to do is make a exe which is searching ( loop search? ) specific directory and is looking for any file which has 1kb in size, when it finds one, it automatically deletes it.

I can't find any reference how to do that, could somebody help with this?
This would be pretty easy using the Boost FileSystem Library.

http://www.boost.org/doc/libs/1_38_0/libs/filesystem/doc/reference.html

They have tools such as boost::filesystem::directory_iterator or boost::filesystem::recursive_directory_iterator that you can use to iterate (search) through a directory. Then you can use boost::filesystem::file_size() to get sizes (in bytes) and boost::filesystem::remove() to delete files.

It would be quite simple.
Thanks for the reply.

I'm not so advanced in the all coding thing, but I have some difficulties to set up the library so it work on code:bloks Ide.

What I did is downloaded the library, downloaded the "Bjam" which I understand builds the boost library O.o, when that was done, I had a new folder in my directory "Bin.v2".
If I done right I linked all the available lib packages in the "Setting >> Compiler and debugger" after it a tried a code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include <boost/regex.hpp>
#include <iostream>
#include <string>

int main()
{
    std::string line;
    boost::regex pat( "^Subject: (Re: |Aw: )*(.*)" );

    while (std::cin)
    {
        std::getline(std::cin, line);
        boost::smatch matches;
        if (boost::regex_match(line, matches, pat))
            std::cout << matches[2] << std::endl;
    }
}


trying to build it, I get error, "boost has not been declared"




I know I made a mistake in the first time trying to setup the lib, because doing like it states in http://www.boost.org/doc/libs/1_39_0/more/getting_started/unix-variants.html#get-boost was not possible, starting at step 5th I did different.

I got the extracted boost_1_39_0.tar.bz2 in /usr/local/lib

tiped in terminal
$ cd /usr/local/lib
$ sudo bjam



after that it automatically started to build files with a .o extension and a lot else.



Is there any other simple way?




Is there any other simple way?
None for Linux/UNIX.

You could also just use system calls, if you're not worried about portability. It will probably be a lot easier for a newbie.
I'm trying to figure it out.

I got an example code which I want to compile using boost, but the are some problems.

1. I type in terminal- $ sudo gedit example.cpp
2. I put my code in it. ( In the example.cpp txt file ), save->close.
3. In terminal I tipe-& c++ -I usr/local/lib/boost_1_39_0 example.cpp -o example \ ~/ boost_1_39_0/stage/lib/libboost_regex-gcc43-mt.a

and then I get the error message:




c++: ~/: No such file or directory
c++: boost_1_39_0/stage/lib/libboost_regex-gcc43-mt.a: No such file or directory
example.cpp:1:27: error: boost/regex.hpp: No such file or directory
example.cpp: In function ‘int main()’:
example.cpp:8: error: ‘boost’ has not been declared
example.cpp:8: error: expected `;' before ‘pat’
example.cpp:13: error: ‘boost’ has not been declared
example.cpp:13: error: expected `;' before ‘matches’
example.cpp:14: error: ‘boost’ has not been declared
example.cpp:14: error: ‘matches’ was not declared in this scope
example.cpp:14: error: ‘pat’ was not declared in this scope



I have all the library files in place, could it be I am typing wrong terminal command?
The compiler can't find where Boost installed the includes. Try to find them in /usr/include. The last time something like that happened to me, the installation put them in a subdirectory there. You may also want to check /usr/local/include
What kind of Includes should I look for?

I have all in usr/local/lib/boost_1_39_0 folder

If I find the "Include" files, how do I use them in terminal for a command?
Topic archived. No new replies allowed.