Does Qt have any platform-independent functionality to accept paths like "~/myfile"?
I know about wordexp, but it would be nice with a platform-independent wrapper.
Edit:
Thank you all for the responses. "~/myfile" was just an example. What I am looking for is functionality to handle file-paths as you would be able to write on the command-line. So on Linux, it should accept "~/myfile", "~otheruser/hisfile", "$VAR/file" etc. On Windows, it should accept "%HOMEDIR%\myfile" etc.
You could probably just replace the tilde with the result of QDir::homePath()? Reference here.
I think that the absolutePath (http://doc.qt.io/qt-5/qdir.html#absolutePath) is the way to do it.
Related
If I do list.files('~') on Linux I get the contents of my home directory.
If I do list.files('%userprofiles%') from Windows, I get an empty character as the return.
How can I use the special directories in this manner on Windows?
This isn't the same as this question because using ~ in Windows gets me %userprofile%/documents which I don't want. As a plan B I can use that and use string manipulation to take out "/documents" but that seems pretty hacky.
I'm not sure if you would consider this "hacky", but you can try something like:
list.files(dirname(path.expand("~")))
From #nongkrong's comments...
Sys.getenv("USERPROFILE") will return the correct directory. Using Sys.getenv() will work for other special directories too. Fortunately it is possible to mix "\\", which Sys.getenv() returns, with "/" which are more convenient to use for full paths.
Is there any way to create a unix FIFO with Go language? There is no Mkfifo, nor Mknod in os package, though I expected named FIFOs are largely used in posix OS's. In fact, there is a function for creating an unnamed FIFO (pipe), but no function for creating named pipes.
Am I the only one who needs them?
In order to get it to work on Linux, I simply did a
syscall.Mknod(fullPath, syscall.S_IFIFO|0666, 0)
It seemed to do the trick.
Here is a reference for the underlying mknod() call
There is a Mkfifo, but it's in the syscall-package :)
Searching through the source gives me the feeling it's not available on anything but OS X and FreeBSD though: http://www.google.com/codesearch#search&q=Mkfifo+package:http://go%5C.googlecode%5C.com
I don't have a unix machine ready to test with. You can use cgo if you like to build a C-interface package which exports it for you.
How can you pick pages from a PDF file?
Pseudo-code synopsis
pick-pages 1,2-69,70-73,100 example.pdf > put_to_new_file.pdf
My best suggestion would be to try something with PDF toolkit - with Split and Merge, and a simple .bat file construction, something like that shouldn't be much hard.
ghostscript, somethign like
gs -q -dBATCH -dNOPAUSE -sDEVICE=pdfwrite -dFirstPage=3 -dLastPage=3 -sOutputFile=fileout.pdf filein.pdf
This is how I've done it with regular expressions. I counted the number of matches for the following regular expressions:
/Type\s*/Page[^s]
Case insensitive, by the way.
You're after pdftk.
Probably this is not a popular method, but this is one way. You can use pdflatex. For example, you can write a tex like:
\documentclass{book}\usepackage{pdfpages}\begin{document}
\includepdf[pages={1,2-10,11}]{pdf.pdf}\end{document}
You can write a small script to automize this.
As part of my CAM::PDF Perl library on CPAN, I bundle a command-line utility deletepdfpage.pl that does the inverse of what you are asking for, with almost the exact same syntax:
deletepdfpage.pl original.pdf 74-99,101- target.pdf
VendorString() doesn't work, it's always Sun Microsystems, even if it is Xorg built for Solaris.
$ xdpyinfo | grep vendor
vendor string: The X.Org Foundation
vendor release number: 10601901
This is xorg-server 1.6.1 on Linux. Hopefully XOrg and XSun on Solaris will differ here.
To output these two fields, xdpyinfo calls the ServerVendor macro to determine the vendor, then parses the return of the VendorRelease macro differently depending on what ServerVendor was.
By the way, what's VendorString()? I don't have a function or macro by that name...
It's possibly a little hacky, but if you look at the list of extensions returned from Xsun and Xorg you should see that Xorg has a few extra XFree86-derived extensions.
xdpyinfo can be used to list the extensions via the command-line to check for differences; programmatically you can use XListExtensions() or XQueryExtension().
(I haven't got a Xsun X Server to hand but I'm pretty sure when I've looked in the past they have differed quite abit).
Thank you!
Oops, VendorRelease() string it is.
Anyway, unfortunately we cannot bet on this string. It changes often enough to have a trouble, for Xsun as well as for Xorg. I have found a solution working (hopefully) for them and for various other (derived) servers like Xvfb, Xnest etc.
Xsun does use a third value in an array of the keysyms for KP_ (numpad) keycodes. Xorg uses 1-st or 2-nd. A sniffer should first, obtain a keycode for a KP_ keysym, for instance XK_KP_7,
second, sniff what is in the XKeycodeToKeysym(d,keycode, [0-3]). Our XK_KP_7 will be on the index 2 for Xsun.
How can I tell unix "find" to include in it's recursive search a folder which is softlinked?
-L . This causes it to follow all symbolic (I assume this is what you mean by soft) links.
Interesting - I hadn't come across '-L' (or the opposite, '-H') before. You can also use '-follow' to do the same job. It can be built into expressions (it always evaluates to true), so you might be able to be more subtle with it that using '-L'. However, I wouldn't worry about that subtlety too much - the '-L' is simpler.
find some more information about unix find command at
http://scripterworld.blogspot.com/2009/07/unix-find-command-with-examples-and.html