Qmake get parent directory - qt

I try to get the parent directory for PWD.
I try ../$$PWD. It does not work.
Initially the task was to get the address of the parent subdir, but so far I can't even downgrade the directory.
TEMPLATE = app
Parent_path = $$PWD //here i get smt like C:/Myproject/project(here is my project.pro), but i need only C:/Myproject

Change your code to
Parent_path = $$PWD/../
OR
Parent_path = $$clean_path($$PWD/../)
# Where `../` is resolved.
Because .. is a hard link to parent directory. Then you can use your Parent_path variable something like this
message($$Parent_path)

Related

How to convert from File to git path?

Im using jgit, log() command, and the addPath(String path) requires me to input a git compatible path, that is, a relative path like src/java/com/foo/Test.java. But what I got is a File object, that will have an absolute path of something like: c:\hello\irrelevant\myproject\src\java\com\foo\test.java.
How to convert from this to the git path? Is there some handy function within jgit itself? I cant find it....
You can use Path::relativize to get the relative path between the file to add and the work directory.
For example:
File workDir = git.getWorkTree(); // e.g. "/path/to/workdir"
File file = new File("/path/to/workdir/foo.txt");
Path relativePath = workDir.toPath().relativize(file.toPath());
assertEquals("foo.txt", relativePath.toString());

How to change to the next above directory

I really would like to know how to change directory to the next file, using 2 dots (/..).
I can go back to previous directory but how to do something like that to go to the next directory WITHOUT THE NAME OF THE FILE PLEASE!
I know it is possbile with the name of the folder but my answer is different, please let me know.
What O.S are you using? In linux ubuntu/Debian distributions (and probably in windows, not sure), you can enter the first child directory by simply typingcd */, this will change your current directory to the first child directory available in alphabetical order, example:
-/home
-alan
-desktop
-music
-alex
-documents
-pictures
-lisa
Assuming your in /home, if you write cd */ in the terminal you will be in /home/alan, because -alan is the first folder/directory available.

Absolute path of the project root directory in Julia

The project root directory of a file located in PROJECT_ROOT/lib/code.jl can be accessed with this code:
root = dirname(dirname(#__FILE__))
Using dirname() twice seems pretty ugly. Is there a better way to do this? With Ruby, I would use this code:
root = File.expand_path('../', File.dirname(__FILE__))
Thanks for making me find out about:
"/"*relpath((#__FILE__)*"/../..","/")
According to ?relpath, it gives a path from the location of the second argument in the file-system, to the first argument. Is this better than the double dirname solution?
A variant of the same niceness is:
normpath(joinpath(#__FILE__,"..",".."))
Closest to Ruby equivalent might be:
realpath(dirname(#__FILE__)*"/..")
I like to use
module Foo
const PROJECT_ROOT = pkgdir(Foo)
end # module
where the definition of PROJECT_ROOT can also be replaced by
const PROJECT_ROOT = dirname(dirname(pathof(Foo)))
Or, you could use
const PROJECT_ROOT = pkdir(#__MODULE__)
I just use
const PROJECT_ROOT = #__DIR__
from inside my _init.jl file, which resides in the project root directory (next to the src directory) and gives you a canonical path.
I get my _init.jl files automatically executed when opening a Julia session from inside that directories by having
isfile("_init.jl") && include(joinpath(pwd(), "_init.jl"))
in my ~/.julia/config/startup.jl file. If you started Julia elsewhere, you have to include("_init.jl") it (or respective relative path) manually.

setRootPath() in QT FIleSystemModel to a file

I'm building a simple file browser using QT, and I can't seem to get the setRootPath() of my model to be set to a file, rather than just a directory.
Ex:
setRootPath("/Users/Foo/Bar") works, but
setRootPath("/Users/Foo/Bar/readme.txt") simply sets the root path to "."
Not sure what I'm missing. Everything else within my application works fine.
You can do this:
QFileInfo m_FileInfo = QString("C:/Users/Foo/Bar/readme.txt");
setRootPath(m_FileInfo.absolutePath());
What we're doing is using QFileInfo to get the absolutePath() of the file. So it'll set the root path to C:/Users/Foo/Bar.

pass permanent parameter to a jar file

I have 3 jars: jar1, jar2 and jar3, in the same path who can change in other pc (ex: c:\prova)
When I run jar1, it moves jar2 in the Windows Sturtup folder.
I want that jar2 simply activate jar3 at every windows startup, but of course it doesn't find jar3 who is remained in the first path.
So I want that jar1 pass a reference (in this case the path c:\prova) to the jar2, when moving it, or at least on the first call to it.
I find it difficoult because:
I can't write the path in a text file in jar2: text files in jars aren't writable.
I can't write the text file in the windows Startup folder: it will be opened at every win startup..
I can't pass the path as a parameter, it will be good for the first call but I can't store this value for the succesive calls.
Sorry for my bad english, thanks for any help!
To add the file Path.txt (with jar3's path) in jar2:
Runtime.getRuntime().exec("jar uf jar2.jar Path.txt");
To read the file in jar2 (Startup is my class name):
String s = "/Path.txt";
is = Startup.class.getResourceAsStream(s);
br = new BufferedReader(new InputStreamReader(is));
while (null != (line = br.readLine())) {
list.add(line);
}
Thank me!

Resources