NextPVR Forums
  • ______
  • Home
  • New Posts
  • Wiki
  • Members
  • Help
  • Search
  • Register
  • Login
  • Home
  • Wiki
  • Members
  • Help
  • Search
NextPVR Forums General General Discussion v
« Previous 1 … 146 147 148 149 150 … 159 Next »
Cygwin Recursive searching Multiple Hard Drives..Help-Non GBPVR Related

 
  • 0 Vote(s) - 0 Average
Cygwin Recursive searching Multiple Hard Drives..Help-Non GBPVR Related
darrin75
Offline

Senior Member

Posts: 558
Threads: 103
Joined: Nov 2004
#1
2005-07-27, 02:45 AM
#include <string>
#include <unistd.h>
#include <sys/types.h>
#include <pwd.h>

#include "TivoManager.hh"
#include "BeaconManager.hh"
#include "Server.hh"
#include "NowShowingCollector.hh"
#include "ShowDatabase.hh"

using namespace std;

string fake_tivo_name = "TivoServer";
string fake_tivo_id = "3510000D03935AD";


ShowDatabase showDb;
TivoManager tivoManager;
BeaconManager beacon( fake_tivo_id, fake_tivo_name, &tivoManager );
Server server( fake_tivo_id, &showDb );
NowShowingCollector nowShowingColl( fake_tivo_id, &tivoManager, &showDb );

int main(int argc, char **argv)
{
string shows_dir;
passwd *pwent;

pwent = getpwnam( getlogin() );
shows_dir = string(pwent->pw_dir);
shows_dir += "/video";

if( argc > 2 )
{
cout << "\n Useage: tivoserver [Shows Directory]\n" << endl;
return -1;
}

if( argc == 2 )
{
shows_dir = argv[1];
if( shows_dir.size() <= 0 )
{
cout << "\n Useage: tivoserver [Shows Directory]\n" << endl;
return -1;
}
}

if( shows_dir[ shows_dir.size()-1 ] != '/' ) {
shows_dir += '/';
}

if( ! showDb.loadLocalShows( shows_dir ) )
{
return -1;
}

beacon.Start();
server.Start();
// tivoManager.AddTivo("2400000E07B847A", "WestonsTivo", addr);

// nowShowingColl.Start();

while(1) sleep(60);

return 0;
}


It got some source here is there anybody out there that can help apply recursive searching to this app. I would really be grafeful even pay..This app will only search one directory in cygwin home/owner/video..Although I can directory a path to a different dir fine, just looking to scan multiple hdrives for the same file type etc. Anyone know Reven old buddy old pal. Can you help.. Thanks

Darrin75
reven
Offline

Posting Freak

Posts: 5,782
Threads: 396
Joined: Sep 2004
#2
2005-07-27, 04:57 AM
the way i do a recursive search (well would, not sure if ive done this ever) would be like
Code:
using System.IO;

// array = the array you are building, this could be an instance variable, or passed, it doesnt really matter, or it could just be the return type.  ref just means reference, ie your not cloning/copying the array as you pass it just pass an pointer to that array so each recursion is using the same object.
// the starting directory
private void recursivedirectory(ref ArrayList array, string directory){
string[] dirs = Directory.GetDirectories(directory);
foreach(string dir in dirs){
recursivedirectory(ref array, dir);  // dir is the new directory;
}
string[] files = Directory.GetFiles(dir);
foreach(string file in files){
if(SomeMatchingCriteria(file)){
array.Add(file);
}
}

// just matches a simple .jpeg file.
private bool SomeMatchingCriteria(string file){
if(file.ToLower().EndsWith(".jpeg"))
return true;
}
}
that would fine every jpeg file in those directories and add them to a single level array. so you couldnt seperate via subfolders etc, for that you could instead have a method like
Code:
private ArrayList recursivedirectory(string directory){
ArrayList array = new ArrayList();
foreach(string dir in Directory.GetDirectories(directory)){
array.Add(recursivedirectory(dir)); // you can tell that its a folder now since the object stored in the arraylist is an arraylist
}

foreach(string file in Directory.getFiles(directory))
if(MatchSomeCriteria(file))
array.Add(file);//and files are of type "string"
}
private void justsomemethodCallingTheRecursiveDirectorySearch(){
ArrayList directories = recursivedirectory("C:\dir\")
}

i doubt that will compile, but thats the basic idea.
jedbob52
Offline

Junior Member

Posts: 4
Threads: 0
Joined: Feb 2005
#3
2005-07-28, 06:29 PM
A different example in C - and a little extra cygwin info (assuming here that showDb.loadLocalShows( shows_dir ) actually does the searching within the directory you pass it - otherwise, you could match via filename using dp->d_name):



#include <sys/stat.h>
#include <dirent.h>

/* this should be safe (as long as passed valid filename retrieved from readdir() - I don't know of any filesystems that allow zero length filenames - and it will short circuit before possibly accessing invalid memory (name[2]) */
#define DOTDIR(name) ('.' == name[0] && ('\0' == name[1] || \
('.' == name[1] && '\0' == name[2])))

int findrecursive(const char *const shows_dir)
{
DIR *dirp;
struct dirent *dp;
struct stat sbuf;
char f_name[PATH_MAX + 1];

/* open directory */
if (NULL == (dirp = opendir(shows_dir))) {
cout << "Error blah" << endl;
return 0;
}


/* read entry by entry from directory */
while(NULL != (dp = readdir(dirp))) {
if (DOTDIR(dp->d_name))
continue;

strcpy(f_name, shows_dir);

if ('/' != f_name[strlen(f_name) - 1])
strcat(f_name, "/");
strcat(f_name, dp->d_name);

/* get stat buffer of name */
if (stat(f_name, &sbuf) < 0) {
cout << "Error blah2" << endl;
return 0;
}

/* check if it is a directory, if so, recurse */
if (S_IFDIR == (S_IFDIR & sbuf.st_mode)) {
/* or you could just add the names to an array, as in reven's example, and search them all later */
if (!findrecursive(f_name))
return(0);
}
}

/* this can also go before the while loop */
if (!showDB.loadLocalShows(shows_dir))
return(0);

return(1);
}



I haven't actually compiled an ran this - but I took this code from something I wrote a long time ago... - so it should work in principle. There may be some additional error checking and such that is missing here, but the main idea is there.

So, I'm not sure exactly how you're trying to go about starting the search, but in cygwin, if you wanted to search all drives, there are a couple possible approaches:

1. findrecursive("/") - I don't know whether doing this in cygwin will include the /cygdrive mount points since they don't show up in an ls of /

2. findrecursive("/cygdrive") - This would certainly search everything (since / really is somewhere within /cygdrive/c usually) - including network drives, etc. - so it may for that reason not be desirable

3. If you specify microsoft-style drive letters to search, you can use the cygwin_conv_to_full_posix_path() function, so if you wanted to search C: and D:, you could do something like:
cygwin_conv_to_full_posix_path("C:\\", path);
findrecursive(path);
cygwin_conf_to_full_posix_path("D:\\", path);
findrecursive(path);

4. You could get a list of volumes, and determine which ones are local, etc., or something like that...

So, I don't know how you plan on initiating the search (with a list of search locations, etc), but anyway, hope this helps at all...
« Next Oldest | Next Newest »

Users browsing this thread: 1 Guest(s)



Possibly Related Threads…
Thread Author Replies Views Last Post
  Multiple instances of NextPVR on Kodi Spaldo 4 1,404 2023-06-01, 09:13 AM
Last Post: Spaldo
  Multiple PIP windows in Firefox Graham 0 1,763 2020-09-25, 11:45 AM
Last Post: Graham
  Multiple Connections Ex Bee MC 1 2,197 2018-08-18, 02:43 AM
Last Post: sub
  Hard Drive Life crossnet 7 3,884 2016-09-08, 06:28 PM
Last Post: crossnet
  windows xp on my gbpvr box jam_zhou 2 2,117 2014-02-14, 09:19 PM
Last Post: mvallevand
  forums.gbpvr.com now my homepage due to olympics... johnsonx42 5 2,809 2014-02-14, 02:30 PM
Last Post: nitrogen_widget
  Life After GBPVR - A Cautionary Tale of Moving to a Cable Company DVR bdgbill 2 2,677 2013-06-01, 11:34 PM
Last Post: mvallevand
  Hard drive with wireless support tieke 0 1,545 2012-11-22, 10:42 PM
Last Post: tieke
  GBPVR to NEXTPVR migration - benefits? ram4x4nut 26 8,829 2012-10-16, 12:07 PM
Last Post: imilne
  Searching forum for my own posts with attachments and deleting the attachments? jksmurf 2 1,620 2012-05-26, 05:45 AM
Last Post: jksmurf

  • View a Printable Version
  • Subscribe to this thread
Forum Jump:

© Designed by D&D, modified by NextPVR - Powered by MyBB

Linear Mode
Threaded Mode