Unoffical empeg BBS

Quick Links: Empeg FAQ | RioCar.Org | Hijack | BigDisk Builder | jEmplode | emphatic
Repairs: Repairs

Topic Options
#364464 - 04/08/2015 04:22 Extracting specific filetype from subdirectories
tanstaafl.
carpal tunnel

Registered: 08/07/1999
Posts: 5544
Loc: Ajijic, Mexico
My eBook directory on a laptop computer contains 4245 directories/subdirectories, each containing one *.mobi file out of the 12,428 files in all.

Is there a simple way (batch file, maybe?) that could go through the eBook directory tree and extract or copy only the 4245 *.mobi files to a separate directory so I can then import them into Calibre?

tanstaafl.
_________________________
"There Ain't No Such Thing As A Free Lunch"

Top
#364465 - 04/08/2015 05:45 Re: Extracting specific filetype from subdirectories [Re: tanstaafl.]
Roger
carpal tunnel

Registered: 18/01/2000
Posts: 5682
Loc: London, UK
Which OS?
_________________________
-- roger

Top
#364466 - 04/08/2015 06:46 Re: Extracting specific filetype from subdirectories [Re: tanstaafl.]
andy
carpal tunnel

Registered: 10/06/1999
Posts: 5914
Loc: Wivenhoe, Essex, UK
I've not used it myself, but this tool looks like it will do what you need:

https://machinewrapped.wordpress.com/smartcopy/
_________________________
Remind me to change my signature to something more interesting someday

Top
#364467 - 04/08/2015 06:53 Re: Extracting specific filetype from subdirectories [Re: andy]
andy
carpal tunnel

Registered: 10/06/1999
Posts: 5914
Loc: Wivenhoe, Essex, UK
Or use PowerShell (included with Windows7/8), something like this:

get-Childitem -recurse -filter *.mobi | Move-Item -Destination c:\temp -WhatIf
_________________________
Remind me to change my signature to something more interesting someday

Top
#364468 - 04/08/2015 11:23 Re: Extracting specific filetype from subdirectories [Re: tanstaafl.]
mlord
carpal tunnel

Registered: 29/08/2000
Posts: 14484
Loc: Canada
Rather than moving the files, this method creates duplicate links for them. If you really want to move them, just replace ln with mv.
Code:
cd ebook_directory
mkdir mobi_books
find . -type f -name \*.mobi -print0 | xargs -0 -i ln {} mobi_books/

Top
#364469 - 04/08/2015 13:30 Re: Extracting specific filetype from subdirectories [Re: mlord]
canuckInOR
carpal tunnel

Registered: 13/02/2002
Posts: 3212
Loc: Portland, OR
Originally Posted By: mlord
Rather than moving the files, this method creates duplicate links for them. If you really want to move them, just replace ln with mv.
Code:
cd ebook_directory
mkdir mobi_books
find . -type f -name \*.mobi -print0 | xargs -0 -i ln {} mobi_books/

Exactly the solution I'd use too, but I'd be willing to bet it's a Windows machine, without a cygwin install.

Top
#364470 - 04/08/2015 15:42 Re: Extracting specific filetype from subdirectories [Re: Roger]
tanstaafl.
carpal tunnel

Registered: 08/07/1999
Posts: 5544
Loc: Ajijic, Mexico
Originally Posted By: Roger
Which OS?
Windows 8.1

tanstaafl.
_________________________
"There Ain't No Such Thing As A Free Lunch"

Top
#364471 - 04/08/2015 16:02 Re: Extracting specific filetype from subdirectories [Re: andy]
tanstaafl.
carpal tunnel

Registered: 08/07/1999
Posts: 5544
Loc: Ajijic, Mexico
Originally Posted By: andy
I've not used it myself, but this tool looks like it will do what you need: https://machinewrapped.wordpress.com/smartcopy/

Unfortunately, it comes really close, but not quite. From the user comments section of the website:

--------------------------------------------

Alex Diaz permalink

Hi,
Great tool, I only have a little problem… How can I make if I want to copy all the files to a single directory (I mean don´t create subfolders in the target directory)…. Can you tell me if there is a way to do that?…. Thanks in advance

Reply

mrsdbooth permalink

Hi Alex, a good question… it’s not a scenario I’d considered, so there’s no provision to do it at the moment I’m afraid!

----------------------------------------------

tanstaafl.
_________________________
"There Ain't No Such Thing As A Free Lunch"

Top
#364472 - 04/08/2015 16:31 Re: Extracting specific filetype from subdirectories [Re: tanstaafl.]
tfabris
carpal tunnel

Registered: 20/12/1999
Posts: 31578
Loc: Seattle, WA
Gah, you guys. It's way way way simpler than that. Assuming I'm understanding the problem correctly:

1. Open a Windows Explorer window which is viewing the parent directory of the source location which contains all the file subdirectories.

2. Open another Windows Explorer window showing the destination directory where you want to put all the files in one place.

3. In the first window, the source window, in the SEARCH box in the upper right corner, type *.mobi

4. Select all (ctrl-A) and drag them to the destination folder.

5. Profit. I mean, wait forever.

Potential problem you should watch out for, other methods will have the same issue: How to handle the situation where the file names are duplicated. That isn't a problem when they're in subdirectories, but becomes an issue when you want to put them all in the same place. For instance, two different books where the file names are "chapter 1.mobi" "chapter 2.mobi" or something like that.
_________________________
Tony Fabris

Top
#364473 - 04/08/2015 16:36 Re: Extracting specific filetype from subdirectories [Re: tanstaafl.]
mtempsch
pooh-bah

Registered: 02/06/2000
Posts: 1996
Loc: Gothenburg, Sweden
Originally Posted By: tanstaafl.

Is there a simple way (batch file, maybe?) that could go through the eBook directory tree and extract or copy only the 4245 *.mobi files to a separate directory so I can then import them into Calibre?


I tend to do something similar (in smaller rscale) when for instance downloading a book series where each title has its own folder. Moving them to the root folder for renaming as per my standard and then dropped into the Book_Archive\Author folder.

Simply go to the root of your current archive, and initiate a search for .mobi, including subfolders. Once it's done, mark all the found files with Ctrl-a, drag and drop to (copy/move/link as per need) new directory. That should not bring along the relative paths of the files, just the file.

Might want to scan through the results before the drag ad drop, in case there might be something matching .mobi not athe end. Not sure if there's a way to tell the search in Explorer that the string must occur at the end of the filename.

Edit:
Ah, beaten by the FAQ meister because I had to go find a Win 8 machine to check behaviour hadn't changed... and *.mobi forces the match to the end/extension.


Edited by mtempsch (04/08/2015 17:23)
_________________________
/Michael

Top
#364474 - 04/08/2015 17:12 Re: Extracting specific filetype from subdirectories [Re: tfabris]
tanstaafl.
carpal tunnel

Registered: 08/07/1999
Posts: 5544
Loc: Ajijic, Mexico
Originally Posted By: tfabris
Gah, you guys. It's way way way simpler than that.
Gah! So simple, I am embarrassed that I didn't think of that. Way to go,Tony!

I didn't have to wait forever, either -- four minutes and five seconds for two gigabytes, 3,675 files. Looks like about 600 of the directories did not have a .mobi file in them, those would be directories whose only contents were subdirectories that did contain the .mobis. Like... directory "John D. Macdonald", containing 21 subdirectories, each subdirectory with a Travis McGee book in it.

The process went quickly because I didn't move the files (which does take forever) but copied them instead. After I run them through Calibre, they'll be copied once again into the Calibre library, after which I can delete the other two copies.

Thank you for the simple solution to something I wasn't smart enough to figure out for myself.

tanstaafl.
_________________________
"There Ain't No Such Thing As A Free Lunch"

Top
#364475 - 04/08/2015 17:19 Re: Extracting specific filetype from subdirectories [Re: mtempsch]
tanstaafl.
carpal tunnel

Registered: 08/07/1999
Posts: 5544
Loc: Ajijic, Mexico
Looks like Tony beat you by five minutes, Michael.

No problem with duplicates or unwanted .mobi strings. My original source is fanatically well organized.

Thanks for the help, even it Tony got in ahead of you. smile

tanstaafl.
_________________________
"There Ain't No Such Thing As A Free Lunch"

Top
#364476 - 04/08/2015 20:12 Re: Extracting specific filetype from subdirectories [Re: tanstaafl.]
tfabris
carpal tunnel

Registered: 20/12/1999
Posts: 31578
Loc: Seattle, WA
Originally Posted By: tanstaafl.
The process went quickly because I didn't move the files (which does take forever) but copied them instead.


If source and destination were all on the same hard drive, the move operation would be the quick one. Since it's just updating the directory location of the file instead of actually data-transferring the contents of the file.

For different hard drives, I would think they'd be about the same speed, with move being only slightly longer than copy (deleting each source file after each move should be quick compared to the move itself).

Anyway. The reason I thought of this is because a similar operation is the only way I can manage my iPhone photos. Iphones split all their files up into a bunch of randomly-named subdirectories, and the only way I can see a plain list of all my photos is to use that search box and type in *.jpg. If I want to make a backup of all the photos, I do that and then reconcile.
_________________________
Tony Fabris

Top
#364477 - 06/08/2015 23:59 Re: Extracting specific filetype from subdirectories [Re: tanstaafl.]
gbeer
carpal tunnel

Registered: 17/12/2000
Posts: 2665
Loc: Manteca, California
I don't remember having to collect all the files into one place before importing them. But it's been a while.
_________________________
Glenn

Top
#364478 - 07/08/2015 00:09 Re: Extracting specific filetype from subdirectories [Re: tanstaafl.]
gbeer
carpal tunnel

Registered: 17/12/2000
Posts: 2665
Loc: Manteca, California
BTW. Calibre can be run in split mode. Where the calibre http server is run on the machine in the closet, and the interactive management front end is run from a portable laptop.

The laptop running the front end need only be able to mount the database folders from the server.
_________________________
Glenn

Top
#364480 - 07/08/2015 21:03 Re: Extracting specific filetype from subdirectories [Re: gbeer]
tanstaafl.
carpal tunnel

Registered: 08/07/1999
Posts: 5544
Loc: Ajijic, Mexico
Originally Posted By: gbeer
I don't remember having to collect all the files into one place before importing them. But it's been a while.
Calibre wants to import files, not directories with files in them. The files are all buried several layers deep in directories, where Calibre doesn't see them.

tanstaafl.
_________________________
"There Ain't No Such Thing As A Free Lunch"

Top