Unix uses / to separate folders but Windows uses \, so I wonder a safe way for cross-platform to concat two paths like /tmp/ + temp_file.xxx.
Just after a minute, I found the answer, File.join (-_-)
Related
We can search files in windows 7 or higher version using the following tool:
(I don't have image uploading privilage. I mean the top-right area in windows file explorer.)
When I search for MATLAB files using "*.m", it not only returns *.m files, but also returns *.mp3, *.mp4 files. Is there any way to show *.m files exclusively?
Thanks!
I assume you used the quotation marks here to show the text you typed, because ironically the exact way how it should work is to put the search in quotation marks...
so
*.m
finds .mp3 as well as .m but
"*.m"
should only find the .m files. Alternatively you could also write
ext:".m"
which would guarantee that only extensions are searched. (Although I am not sure if this is ever necessary here, because while windows can have a dot in the filename and also can have files without extensions I am not sure if it is possible to have both at the same time.)
using the following
"*.m"
will solve your problem.You can find more information on regex to be used in msdn in the following link .Advanced query syntax
Above that, you can also take advantage of the wildcard character *.
For example, if you want to search for a file with a name ending with 024 or starting with 024 then you can put in the search box like *024.* or 024*.* respectively.
Here the * after . represents files with any extensions, if you want particular then mention extension line 024.png.
Explorer don't have a function of finding with RegEx.
You need to use Power-Shell instead of Win Explorer;
for example: where '(?i)Out' is a regex
Get-ChildItem -Path e:\temp -Recurse -File | Where-Object { $_.Name -match '(?i)Out' }
alternatively you can just simply search for your extension like this:
.extension
eg:
typing .exe will give you all the files with .exe extensions in a folder.
PS: Typing .xml OR .vmcx will give you both type of files. It is useful if you seek to make an archive of different kinds of files stored in different folders or locations.
You can get close to proper regex support from the mostly awesome Cygwin, and as a bonus you get most every linux tool running natively on linux. But it still doesnn't know that .* means "zero or more of anything", ^ means the start of a line (and $ the end), so some things are still weird.
And a startlingly large bunch of weird corner cases that only deranged perl programmers notice fail the test.
So many other things it gets wrong, but it's more workable than anything in any windows OS, plus you get perl, grep, diff, wget, curl, etc. -- the whole GNU lib for free.
If you want a full on bash shell with proper respect for regex, install the super neet-o Bash for Windows 10
Either will do what you want. And they're a billion times faster than that stupid search bar that takes off at 100 mph then crawls to 1 pixel per 10 minutes near the end.
I was wondering how does a utility like this one redirects a folder to a driver letter?
PS. I need this done with C/C++/MFC.
It probably uses DefineDosDevice, as an ordinary subst command does.
I want to have my C++ application to enable package autoloading for all ActiveTcl packages in C:\Tcl\lib. I pass below tcl command to Tcl_Eval() in my C++ code. And expect "package require <package name>" will automatically find the package and load it.
set ::auto_path [file join {C:\Tcl\lib}]
But it didn't work as what it does in TCL shell - TCL shell looks for pkgIndex.tcl in auto_path, so when "package require", it can find the right package or shared libs. Is it possible to make it work in C++ application? Or is there any better way?
OK, I think I know what the problem might be. The auto_path is a Tcl list of directories — the code that uses it iterates over the list with foreach — that are searched for packages (and auto-loaded scripts, an old mechanism that I think is rather more trouble than it's worth). Yet you're using a single element, the output of that file join. This wouldn't usually matter on platforms other than Windows, as the directory separator is / there (and that's just an ordinary non-whitespace character to Tcl) but on Windows the directory separator is \ and that's a list metasyntax character to Tcl.
What does this mean? Well, after:
set ::auto_path [file join {C:\Tcl\lib}]
We can ask what the things of that list are. For example, we can print the first element of the list…
puts [lindex $::auto_path 0]
What does that output? Probably this:
C:Tcllib
OOooops! The backslashes have been taken as quoting characters, leaving an entirely non-functioning path. That won't work.
The fix is to use a different way to construct the auto_path. I think you'll find that this does what you actually want:
set ::auto_path [list {C:\Tcl\lib}]
Though this is an alternative (still using list; it's best for trouble-free list construction in all cases):
set ::auto_path [list [file normalize {C:\Tcl\lib}]]
(My bet is that you're trying to use file join as a ghetto file normalize. Don't do that. It's been poor practice for a long time now, especially now that we have a command that actually does do what you want.)
What is the correct way to include files
#include "../myDirecoty/myFile.h"
or
#include "..\myDirecoty\myFile.h"
the difference is the direction of "/" or "\".
This is the correct way:
#include "../myDirecoty/myFile.h"
There is no difference, but the first form is more "clear" because sometime people thinks to \ as an escaping character in string (but include path are not strings)
normal slashes "/", best compatible
From what I've seen looking through the code on my computer, you should use forward slashes ('/').
The backslash \ is used on Windows and DOS, while the slash / is used on all UNIX/POSIX compatible systems (like Linux and Mac OS X). So the later can produce a file-not-found error on non-Windows systems. AFAIK all Windows compiler do support the slash /, so this is one to use.
Edit: See also this SO question.
This question already has an answer here:
Closed 10 years ago.
Possible Duplicate:
Qt equivalent of PathAppend?
Short story: does Qt 4 have an analog of Python's os.path.join?
Long story: I need to add a relative path to the application directory, QCoreApplication::applicationDirPath() in the Right Way (TM), so that the code doesn't depend on the file system directory separator character.
Is merely joining QStrings and using "/" as the separator a good solution?
You can either use "/" directly or use QDir::separator(). But in general use a QDir for this (which translates "/" to the platform specific path separator for you).
From Qt 4.6 QDir documentation,
Qt uses "/" as a universal directory separator in the same way that "/" is used as a path separator in URLs. If you always use "/" as a directory separator, Qt will translate your paths to conform to the underlying operating system.
So, I guess QDir will be helpful for you.
Just use "/" when staying in the Qt world.
To convert the path for non-Qt classes and functions etc., use QDir::toNativeSeparators( path ).