Find and list all files/folders in a folder in Haxe - haxe

This question is in principal the same like these ones here
How to read all files in a folder from Java?
How do I list all files of a directory?
...
But is there a way to do the same in on sys target platforms in Haxe, without running ls / dir via sys.io.Process and parsing the results?

Yes, you can use sys.FileSystem.readDirectory(path) for this.
Returns the names of all files and directories in the directory specified by path.
If path does not denote a valid directory, an exception is thrown.
If path is null, the result is unspecified.
If you need files to be listed recursively, this article from the Haxe Code Cookbook is a good reference (there's a section titled "Recursive loop through all directories / files").

Related

Can I include a folder relative to the current directory in PATH in Powershell?

I run a lot of node projects and often have binaries located in:
.\node_modules\.bin
...relative to the projects folder. I'd like to be able to have PATH always include these directories, if they exist. I don't want to include other directories, just the one relative to the current directory. I'm familiar with
Add-PathVariable from PSCX and other Powershell basics, but how do I include a folder relative to the current dir in PATH?
Edit: as mentioned in the question, already, I expect the path to stay updated as the directory changes. This is not simply asking about how to use pwd.
You can use a relative path in Env:PATH and the binaries found will update dynamically:
Eg:
$env:PATH += ';.\node_modules\.bin'
Or with the PowerShell Community Extensions (PSCX):
Add-PathVariable '.\node_modules\.bin'
Unlike using $(pwd) the . is not immediately resolved to an absolute path, so PATH is always relative to the current working directory.
Testing this:
$ which uuid
C:\Users\username\Documents\myapp\node_modules\.bin\uuid.cmd
Then changing directory, uuid now refers to a program in a different dir:
$ cd ..\blog\
$ which uuid
C:\Users\username\Documents\blog\node_modules\.bin\uuid.cmd
It's also possible to persistently change PATH in the user or system environment:
[Environment]::SetEnvironmentVariable(($env:PATH + ';.'), 'User')
or
[Environment]::SetEnvironmentVariable(($env:PATH + ';.'), 'Machine')
Security note: when entering a command Windows will automatically search all directories in $env:PATH for files with one of the extensions listed in $env:PATHEXT and execute the first match it finds. Depending on where exactly in the search path you placed . that may even supersede system executables.
You may want to take a look at how to use package installed locally in node_modules for alternative approaches.

no such file or directory (cygwin)

I am trying to install a solver (SCIP) with cygwin. After unpacking the folder consists of another 5 folders. The manual says I have to go in folder A and use make. Here, I get the message that one file was not found:
zimpl/bool.h: No such file or directory
This file is in folder B in the path zimpl/src/bool.h. How can I link this file from folder B that cygwin can use it while using make in folder A?
The support says:
Blockquote The error you postet looks like your zimpl softlink is incorrect. If you use a relative path, make sure that it is relative to the position where
the link is created. Most softlinks are created directly in the lib
directory, the zimpl softlink, however, is in a subdirectory of the lib
directory, so you have to go up two directories to get to the main SCIP
directory.
However I am not sure how to check the softlinks.
Thanks!

Copying symbolic links but pointing to same files(copied) but different target base directories

I am trying to create a test environment by updating it with another test environment files. Heres my situation:
I have a directory SRC. It has directories "test_bundles" and "tools_bundles" which has all the required builds. Additionally, SRC has "latest" directory which has files "test_bundle_1", "tools_bundle_1" etc. which points to specific builds within directories "test_bundles" and "tools_bundles", i.e., symbolic links.
Now on a different Linux system, I have DEST directory which is regularly updated with contents of "test_bundles" and "tools_bundles" from the SRC directory. I also want to have "latest" directory in DEST that has same files as in "latest" within SRC directory, however, points to builds (these builds are same) inside "test_bundles" and "tools_bundles" within the DEST.
Note that files change their links to different builds and moreover, new files get added to "latest" within SRC as well. So whenever I do copy operation it should update everything.
I dont know what to call this. Am I trying to copy the SRC "latest" to DEST "latest" files (symbolic links) with links to different parent directory structure.
Note that my script is doing good by updating "test_bundles" and "tools_bundles". I just need a way for "latest" files with the test environment uses different base directories.
If the links in latest are relative there is nothing special that
needs to be done - parent directory names do not matter. – Michał
Politowski
Actually its the opposite, the links are not relative rather the
parent directory structure(tree) is different – user3685188
What Michał Politowski surely meant to suggest is that you should make the symbolic links relative in order to have your problem solved - and that is the most sane solution.

SCons: Forcing SCons to duplicate files

I have a header-only library consisting of a folder hierarchy and a bunch of .hpp files I'd like to install. My problem is, that scons does not copy the folder into the build folder.
Here is what my directory layout looks like:
root
SConstruct
subdir
SConscript
the_lib
subdir_a
header_a.hpp
subdir_b
header_b.hpp
build
(...)
Here is what I do in subdir/SConscript:
all_headers = []
for root, dirnames, filenames in os.walk('.'):
for filename in fnmatch.filter(filenames, '*.hpp'):
fn = os.path.join(root, filename)
all_headers.append((fn, root))
for f, d in all_headers:
install.AddHeader( f, d )
I do this to get the filenames along with their relative paths and then, I use the installer I found in the scons wiki the other day.
Observation: all_headers remains empty because the the_lib folder does not get copied. I tired subdir_env.Dir('the_lib'), but did not change a thing.
After running the script, I have the_lib/SConscript in my build folder, but nothing else. Of course I can understand that my filesystem walk does nothing in that case.
Can anyone help me?
UPDATE
The only way out I found was to run a find -name "*.hpp" and paste the result into my SConscript. Works like a charm now, but since the library is an external one (and maybe some files are added or removed), I thought of a more generic solution without the need to know all headers by name.
The first thing I thought of was to use the SCons Install() builder, but that is to install actual SCons targets in different locations, and since these header files are not targets, that wont work.
So, in this case, you can use what is called the SCons Copy Factory.
if build is a VariantDir then you don't need to copy the file yourself, scons will do it if the header is used in any Builder.
If you want to a list of the files you can use env.Glob('*/*.hpp') (but wildcards won't traverse directories, so you need to know the depth)

Multiple locations within a folder hierarchy to run SCons from

So far, I've only seen examples of running SCons in the same folder as the single SConstruct file resides. Let's say my project structure is like:
src/*.(cpp|h)
tools/mytool/*.(cpp|h)
What I'd like is to be able to run 'scons' at the root and also inside tools/mytool. The latter compiles only mytool. Is this possible with SCons?
I assume it involves creating another SConstruct file. I've made another one: tools/mytool/SConstruct
I made it contain only:
SConscript('../../SConstruct')
and I was thinking of doing Import('env mytoolTarget') and calling Default(mytoolTarget), but running it with just the above runs in the current directory instead of from the root, so the include paths are broken.
What's the correct way to do this?
You can use the -u option to do this. From any subdirectory, scons -u will search upwards in the directory tree for an SConstruct file.

Resources