Possible to read files with wildcard in the path name? - sql

For example, /path/to/*/file can you use SQL to read a file using a wildcard to fill in the absolute path? This is for a situation where I there is one component in the path which changes unpredictably.

I think the answer is no. But if you can look up the valid options by querying the file structure you could then loop around the results. However I would suggest that any system that employed this approach would be wide open to hackers.

Related

Get file type of given file - based on contents

OK, it may sound fairly straightforward but I'm still not sure how to go about it.
I know it's possible to check file type based on file extensions, using UTIs (e.g. Get the type of a file in Cocoa).
However, I need to be able to get the file type (in more general terms, like "text", "image", "else"), depending on the content.
Is that possible?
Any ideas?
One route forward is to call the file command and parse its output, but that is fairly horrible, and I wouldn't do that as it's slow and you are susceptible to changes in the output.
The file command uses a pretty extensive database of byte patterns to test the contents of the file and I would be tempted to implement my own internal version of it, or use this library (which I think might need some work before it works under OSX).

Content types understood by an application

Given an application path (or NSBundle to an application, etc), is there a way to easily/efficiently determine what content types that application can open?
My initial attempt was to read the application's Info.plist file and extract the content types listed under the kUTExportedTypeDeclarationsKey key. However, there are some flaws with this approach which I haven't been able to work around.
Not all applications use this key. For example, BBEdit does not, but instead lists a whole bunch of recognized file extensions.
UTIs are case-sensitive. Pages, for example, lists com.apple.iWork.Pages.pages as an exported content type, yet no Pages document actually has that type listed in its content type tree. Documents use com.apple.iwork.pages.pages, which is defined by the iWork quicklook generator (at /Library/QuickLook/iWork.qlgenerator).
In know that with some of the LaunchServices functions (LSCopyApplicationURLsForURL(), LSCopyApplicationForMIMEType(), etc), I can get the applications that can open a file (or a file type), but I'd like to do the inverse. (Perhaps I'll have to resort to parsing the output of lsregister -dump?)
Perhaps a simpler way to phrase the question would be: Given an application, what's the easiest way to find all files that it can open?
Any suggestions?
Take a look at LaunchServices and the provided LSCanRefAcceptItem() API.
It seems using the LSItemContentTypes key is the preferred method post-10.4.
Apple: Document-Based Applications

How to enumerate paths for all NTFS hard links pointing to a file?

I can use GetFileInformationByHandle to determine the number of hard links associated with a file. How can I enumerate the paths which make up those links?
For example, if C:\TEMP_1.BIN and C:\TEMP_2.BIN are hard links to the same content, and I determine from GetFileInformationByHandle that C:\TEMP_1.BIN has nNumberOfLinks=2, how can I discover the path for the other link? (e.g. C:\TEMP_2.BIN)
GetFileInformationByHandle:
http://msdn.microsoft.com/en-us/library/aa363788%28v=VS.85%29.aspx
I think you're looking for FindFirstFileNameW, which tells you all of the names a file has.

Find duplicate PDFs

I'm looking for a utility that will help me find duplicate PDFs. The problem: I have a 1000s of PDF files. Some are duplicates. They are not easy to detect due differing files names and small differences in file size. Is there a utility/algorithm/library that can help me find the duplicates or show me files that are very similar (or degree of difference)?
Create an MD5 hash for each file and store it in a database. Identical files will then sort next to each other, or you can quickly search for a pre-existing key.
The problem is not yet solved in any way. What I do, is I use fdupes http://premium.caribe.net/~adrian2/fdupes.html to find exact duplicates.
But most of all, I use a workflow which minimizes duplicates. Every document that enters my system gets indexed with this perl-script I wrote: http://seegras.discordia.ch/Programs/fileindex which puts some name and an md5-sum of it into ~/.fileindex.md5 Now I can change metadata of the local PDF-files or whatever (and run fileindex again), and whenever I accidently download the same file again, I will stil lhave the md5-sum of the original file, and thus can detect whether it's a duplicate.
There's also exif-meta and exif-rename on http://seegras.discordia.ch/Programs/ which help with setting PDF metadata and with renaming PDF-files according to metadata; and if you're tagging all the files correctly, you will end up with duplicate filenames, indicating that they might be the same document within a different file.
If the files were created by the different tools, they could look the same but generate very different results because they are structured totally differently. I made some suggestions in a blog article at https://blog.idrsolutions.com/2010/09/comparing-2-pdf-files/
DiffPDF looks like something that might help you.
I remember that there is a UNIX utility called pdf2txt (see the package poppler-utils). You can try to extract the text from the files and make a textual diff.

How do I store strings permanently? After the app is closed?

I'm trying to figure out how to do this as I'm not sure what's the proper way of doing this.
I've got several strings that I want to store/save permanently, even after the application is closed. How should I proceed? Do I read or write from a textfile?
I believe you're looking for a feature known as Application Settings. This feature will take care of storing settings between instances of the application. The manner in which it stores settings is ClickOnce and User aware so it takes much of the problems out of the picture.
Here's a link to an overview on the topic
http://msdn.microsoft.com/en-us/library/c9db58th(VS.80).aspx
Use My.Settings
Yes, you might store it in a simple text file or use a settings file.
Take a look at Application Settings:
http://msdn.microsoft.com/en-us/library/0zszyc6e.aspx
I store what I need in a plain text file. I use my own format: First line: lenght of the array or the number of bytes/lines the data needs to be stored. Second line: data types. third line: directories or path info. At the end I store the data.
That's because programming languages can read by characters or by lines. C++ considers either whitespaces and lines.
SQL or Access is when you need to store more complex data than just strings or arrays.
Yes, I'd store it in some form of text file, then you can read it on load. It's very easy to implement in Visual Basic and you might even find some samples in Codemonkeys or similar. I'd avoid using the registry. Of course if you want, you could also use some sort of database (Access, SQLITE, etc.) to store the values. But that depends upon the type of data and how much do you need to read/write from it.
yes you can write to a text file, or try SQLite, which can let your VB program have database capabilities.
http://www.google.com/search?hl=en&q=visual+basic+sqlite&btnG=Search