LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 06-28-2013, 05:29 PM   #1
g_paschoal
Member
 
Registered: Oct 2009
Posts: 131

Rep: Reputation: 15
C++ listening to linux folder


I need a program that will need to be listening in a linux folder for new files and then take the file to be an argument of my program and process it (do the rest of the stuffs)....

how can do it in C++ ? Thank You
 
Old 06-28-2013, 11:34 PM   #2
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,862
Blog Entries: 1

Rep: Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869
inotify is your friend
 
Old 07-03-2013, 04:35 PM   #3
g_paschoal
Member
 
Registered: Oct 2009
Posts: 131

Original Poster
Rep: Reputation: 15
Thanks for the helping...

I am not a good c++ programer.. in fact I am just begging...

The examples I see from internet all is for add the watched folder as argument to the main. And then use that argument on inotify_add_watch, like that:

wd = inotify_add_watch(fd, argv[1], IN_CREATE | IN_MODIFY | IN_DELETE);

However I don't want to use an argument. I will specify the path myself. But it is not working. I should put a "const char" but no matter what I tried nothing works....

wd = inotify_add_watch(fd, "/test", IN_CREATE | IN_MODIFY | IN_DELETE); --> did NOT work

if I declare variable for example:
const char testDIR = "/test";
wd = inotify_add_watch(fd, testDIR , IN_CREATE | IN_MODIFY | IN_DELETE); --> did NOT work

If I use pointer also it does not work
const char *testDIR = "/test";
wd = inotify_add_watch(fd, *testDIR , IN_CREATE | IN_MODIFY | IN_DELETE); --> did NOT work


Can you help me? Thanks in advance.
 
Old 07-04-2013, 09:33 AM   #4
g_paschoal
Member
 
Registered: Oct 2009
Posts: 131

Original Poster
Rep: Reputation: 15
Never mind I got it working...

The correct is

const char* testDIR = "/test";
 
Old 07-04-2013, 05:35 PM   #5
SaintDanBert
Senior Member
 
Registered: Jan 2009
Location: "North Shore" Louisiana USA
Distribution: Mint-20.1 with Cinnamon
Posts: 1,771
Blog Entries: 3

Rep: Reputation: 108Reputation: 108
Quote:
Originally Posted by g_paschoal View Post
Never mind I got it working...

The correct is
Code:
const char* testDIR = "/test";
Remember that in the 'main' function, char * argv[] which is an array of pointers to char is a hold-over from the olden-days of plain-C.
I've written lots of plain-C and a fair amount of C++. Many libraries still rely on the plain-C arguments so this exact issue continues to trip folks.

Don't forget to mark your thread [SOLVED] if that is the case.

Also, if you can, consider posting your utility -- or the relevant fragment to this thread so that others can learn too.

Cordialement,
~~~ 8d;-Dan
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
make multiple folder on samba linux & each folder can be access each person only Aneesh.T .S Linux - Server 1 01-31-2013 06:01 PM
Need Perl script to get files from Linux Samba share folder to Windows folder kowsi Programming 1 10-10-2012 05:57 PM
opening folder Windows Folder in Red Hat Linux TEXT MODE janbaztaimur Linux - Newbie 8 05-17-2011 04:34 PM
rmiregistry on linux not listening Cyber Maid Linux - Software 9 03-26-2008 07:50 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:37 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration