{"id":24504339,"url":"https://github.com/vegardit/haxe-files","last_synced_at":"2026-02-02T16:02:39.823Z","repository":{"id":31877056,"uuid":"129808433","full_name":"vegardit/haxe-files","owner":"vegardit","description":"A haxelib for cross-platform filesystem operations.","archived":false,"fork":false,"pushed_at":"2025-10-18T22:41:17.000Z","size":269,"stargazers_count":48,"open_issues_count":0,"forks_count":9,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-10-19T12:17:25.356Z","etag":null,"topics":["filesystem","haxe","haxelib"],"latest_commit_sha":null,"homepage":null,"language":"Haxe","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/vegardit.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.txt","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2018-04-16T21:32:06.000Z","updated_at":"2025-10-18T22:41:21.000Z","dependencies_parsed_at":"2025-06-15T22:40:05.965Z","dependency_job_id":"b2aa13af-6590-456d-b459-30bb32459cdf","html_url":"https://github.com/vegardit/haxe-files","commit_stats":null,"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"purl":"pkg:github/vegardit/haxe-files","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vegardit%2Fhaxe-files","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vegardit%2Fhaxe-files/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vegardit%2Fhaxe-files/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vegardit%2Fhaxe-files/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/vegardit","download_url":"https://codeload.github.com/vegardit/haxe-files/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vegardit%2Fhaxe-files/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29015094,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-02T14:58:54.169Z","status":"ssl_error","status_checked_at":"2026-02-02T14:58:51.285Z","response_time":58,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["filesystem","haxe","haxelib"],"created_at":"2025-01-21T23:23:11.150Z","updated_at":"2026-02-02T16:02:39.796Z","avatar_url":"https://github.com/vegardit.png","language":"Haxe","funding_links":[],"categories":[],"sub_categories":[],"readme":"# haxe-files - cross-platform filesystem operations\n\n[![Build Status](https://github.com/vegardit/haxe-files/workflows/Build/badge.svg \"GitHub Actions\")](https://github.com/vegardit/haxe-files/actions?query=workflow%3A%22Build%22)\n[![Release](https://img.shields.io/github/release/vegardit/haxe-files.svg)](http://lib.haxe.org/p/haxe-files)\n[![License](https://img.shields.io/github/license/vegardit/haxe-files.svg?label=license)](#license)\n[![Contributor Covenant](https://img.shields.io/badge/Contributor%20Covenant-v2.1%20adopted-ff69b4.svg)](CODE_OF_CONDUCT.md)\n\n1. [What is it?](#what-is-it)\n1. [The `Path` class](#path-class)\n1. [The `File` class](#file-class)\n1. [The `Dir` class](#dir-class)\n1. [The `GlobPatterns` class](#globpatterns-class)\n1. [File watching](#file-watching)\n1. [Installation](#installation)\n1. [Using the latest code](#latest)\n1. [License](#license)\n\n\n## \u003ca name=\"what-is-it\"\u003e\u003c/a\u003eWhat is it?\n\nA [haxelib](http://lib.haxe.org/documentation/using-haxelib/) for consistent cross-platform filesystem operations and proper Windows-/Unix-style path handling.\n\nAll classes are located in the package `hx.files` or below.\n\nThe library has been extensively unit tested (over 500 individual test cases) on the targets C++, C#, [Eval](https://haxe.org/blog/eval/), [HashLink](https://hashlink.haxe.org/),\nJava, JavaScript ([Node.js](https://nodejs.org) and PhantomJS), Lua, [Neko](https://nekovm.org/), [PHP](https://www.php.net/) 7 and [Python](https://www.python.org/) 3.\n\n**Note:**\n* When targeting [Node.js](https://nodejs.org) the [hxnodejs](https://lib.haxe.org/p/hxnodejs) haxelib is required.\n* When targeting [PhantomJS](https://phantomjs.org) the [phantomjs](https://lib.haxe.org/p/phantomjs) haxelib is required.\n* Flash/Air is currently not supported.\n\n### Haxe compatiblity\n\n|haxe-files      |Haxe           |\n|----------------|---------------|\n|1.0.0 to 1.2.1  |3.4.2 or higher|\n|2.0.0 or higher |4.0.5 or higher|\n|4.0.0 or higher |4.2.0 or higher|\n\n\n## \u003ca name=\"path-class\"\u003e\u003c/a\u003eThe `Path` class\n\nInstances of the [hx.files.Path](https://github.com/vegardit/haxe-files/blob/master/src/hx/files/Path.hx)  class represent the path to a file or directory on the local file system.\nIt can be seen as an improved and extended version of the built-in [haxe.io.Path](http://api.haxe.org/haxe/io/Path.html) class.\nIn contrast to functions provided by haxe.io.Path, there are no situations where the result of a function is unspecified.\n\nThere exist two implementations:\n- `haxe.io.Path.WindowsPath` for Windows path, i.e. backslash is used as directory separator and paths starting with a drive letter or a UNC path are considered absolute\n- `haxe.io.Path.UnixPath` for Unix/Linux style paths, i.e. slash is used as directory separator and paths starting with a slash are considered absolute.\n\n```haxe\npackage com.example;\n\nimport hx.files.*;\n\nclass MyClass {\n\n   static function main() {\n      var p = Path.of(\"./mydir/myfile.txt\");     // constructs a path compatible with the local operating/file-system\n      var p = Path.unix(\"/mydir/myfile.txt\");    // constructs a Unix-style path\n      var p = Path.win(\"C:\\\\mydir\\\\myfile.txt\"); // constructs a Windows-style path\n\n      p.filename;      // returns \"myfile.txt\"\n      p.filenameExt;   // returns \"txt\"\n      p.filenameStem;  // returns \"myfile\"\n      p.isAbsolute;    // returns true\n      p.exists();      // returns true or false depending on physical existance of the path\n      p.isFile();      // returns true if exits and points to a file\n      p.isDirectory(); // returns true if exits and points to a directory\n      p.parent;        // returns Path object pointing to \"C:\\\\mydir\"\n      p.root;          // returns Path object pointing to \"C:\\\\\"\n\n      // path joining\n      var p = Path.win(\"C:\\\\mydir\");\n      p.join(\"project1\\src\");  // returns Path object pointing to \"C:\\\\mydir\\\\project1\\\\src\"\n\n      // getting absolute path\n      var p = Path.of(\"mydir\");\n      p.getAbsolutePath();   // returns the absolute path as string\n\n      // normalizing a path\n      var p = Path.unix(\"aaa/bbb/ccc/../../ddd\");\n      p.normalize();   // returns Path object pointing to \"aaa/ddd\"\n\n      // ellipszing\n      Path.unix(\"/home/user/foo/bar\").ellipsize(15);           // returns \"/home/.../bar\"\n      Path.win(\"C:\\\\Users\\\\Default\\\\Desktop\\\\\").ellipsize(15); // returns \"C:\\...\\Desktop\"\n   }\n}\n```\n\n\n## \u003ca name=\"file-class\"\u003e\u003c/a\u003eThe `File` class\n\nInstances of the [hx.files.File](https://github.com/vegardit/haxe-files/blob/main/src/hx/files/File.hx)  class represent regular files on the local file system.\n\n```haxe\npackage com.example;\n\nimport hx.files.*;\n\nclass MyClass {\n\n   static function main() {\n\n      var f = Path.of(\"mydir/myfile.txt\").toFile(); // converting a Path instance to a File instance\n      var f = File.of(\"mydir/myfile.txt\");          // creating a File instance from a String path\n\n      f.touch();               // create an empty file or update the modification timestamp\n      f.writeString(\"Hello \"); // sets the file's content\n      f.appendString(\"world!\");\n\n      f.size(); // returns the file size\n\n      f.copyTo(\"mydir/myfile2.txt\");              // throws an exception if myfile2.txt exists already\n      f.copyTo(\"mydir/myfile2.txt\", [OVERWRITE]); // replaces myfile2.txt if it exists already\n\n      f.delete();  // deletes the file\n\n      var f2 = f.moveTo(\"otherdir/MY_FILE.txt\");\n      f.exists();  // returns false\n      f2.exists(); // returns true\n   }\n}\n```\n\n\n## \u003ca name=\"dir-class\"\u003e\u003c/a\u003eThe `Dir` class\n\nInstances of the [hx.files.Dir](https://github.com/vegardit/haxe-files/blob/main/src/hx/files/Dir.hx)  class represent directories on the local file system.\n\n```haxe\npackage com.example;\n\nimport hx.files.*;\n\nclass MyClass {\n\n   static function main() {\n\n      var d = Path.of(\"myproject\").toDir(); // converting a Path instance to a Dir instance\n      var d = Dir.of(\"myproject\");          // creating a Dir instance from a String path\n\n      p.setCWD();    // changes the current working directory\n      d.listDirs();  // returns an array of Dir instances for contained directories (non-recursive)\n      d.listFiles(); // returns an array of File instances for contained files (non-recursive)\n\n      d.findFiles(\"src/**/*.hx\");          // returns an array with all Haxe files in the src dir\n      d.findFiles(\"assets/**/*.{js,css}\"); // returns an array with all JS/CSS files in the assets dir\n\n      // recursively visit all contained files and directories\n      d.walk(\n         function(file) {\n            trace(file);\n         },\n         function(dir) {\n            trace(dir);\n         }\n      );\n\n      d.copyTo(\"myproject2\");                     // recursively copy the directory\n      d.copyTo(\"myproject2\", [OVERWRITE]);        // delete myproject2 and recursively copy the directory\n      d.copyTo(\"myproject2\", [MERGE]);            // merge the files and folders into myproject2 but skip conflicting files\n      d.copyTo(\"myproject2\", [MERGE, OVERWRITE]); // merge the files and folders into myproject2 and replace conflicting files\n\n      d.delete(true);  // recursively delete the directory\n   }\n}\n```\n\n\n## \u003ca name=\"globpatterns-class\"\u003e\u003c/a\u003eThe `GlobPatterns` class\n\nThe [hx.files.GlobPatterns](https://github.com/vegardit/haxe-files/blob/main/src/hx/files/GlobPatterns.hx) class contains static methods to convert\n[glob patterns](https://en.wikipedia.org/wiki/Glob_(programming)) into regular expressions.\n\n```haxe\npackage com.example;\n\nimport hx.files.*;\n\nclass MyClass {\n\n   static function main() {\n      GlobPatterns.toRegEx(\"*.txt\");      // returns == \"^[^\\\\\\\\^\\\\/]*\\\\.txt$\"\n      GlobPatterns.toRegEx(\"*file*\");     // returns \"^[^\\\\\\\\^\\\\/]*file[^\\\\\\\\^\\\\/]*$\"\n      GlobPatterns.toRegEx(\"file?.txt\");  // returns \"^file[^\\\\\\\\^\\\\/]\\\\.txt$\"\n      GlobPatterns.toRegEx(\"file[A-Z]\");  // returns \"^file[A-Z]$\"\n      GlobPatterns.toRegEx(\"file[!A-Z]\"); // returns \"^file[^A-Z]$\"\n\n      GlobPatterns.toEreg(\"src/**/*.hx\").match(\"src/haxe/strings/Char.hx\");            // returns true\n      GlobPatterns.toEreg(\"assets/**/*.{js,css}\").match(\"assets/theme/dark/dark.css\"); // returns true\n      GlobPatterns.toEreg(\"SystemOut[0-9].log\").match(\"SystemOut1.log\");               // returns true\n      GlobPatterns.toEreg(\"SystemOut[!0-9].log\").match(\"SystemOut1.log\");              // returns false\n   }\n}\n```\n\n\n## \u003ca name=\"file-watching\"\u003e\u003c/a\u003eFile watching\n\nImplementations of the [hx.files.watcher.FileWatcher](https://github.com/vegardit/haxe-files/blob/main/src/hx/files/watcher/FileWatcher.hx)\ninterface allow you to monitor the file system for create/delete/change events.\n\nThe [hx.files.watcher.PollingFileWatcher](https://github.com/vegardit/haxe-files/blob/main/src/hx/files/watcher/PollingFileWatcher.hx) class\nscans the file system in intervals to recursively determine file changes. This is a rather inefficient way but works cross-target.\n\nWith Java7 or higher the [hx.files.watcher.JavaFileWatcher](https://github.com/vegardit/haxe-files/blob/main/src/hx/files/watcher/JavaFileWatcher.hx)\nbased on [WatcherService](https://docs.oracle.com/javase/7/docs/api/java/nio/file/WatchService.html) is available.\nIt is more efficient but has some limitations as documented in the source code.\n\nOther target-specific implementations can be provided in the future:\n* For C++ based on [fswatch](https://emcrisostomo.github.io/fswatch/)\n* For Python based on [watchdog](https://pypi.org/project/watchdog/)\n\n```haxe\npackage com.example;\n\nimport hx.concurrent.executor.Executor;\nimport hx.files.*;\nimport hx.files.watcher.*;\n\nclass MyClass {\n\n   static function main() {\n\n      var ex = Executor.create(); // executor is used to schedule scanning tasks and\n      var fw = new PollingFileWatcher(ex, 100 /*polling interval in MS*/);\n\n      // register an event listener\n      fw.subscribe(function (event) {\n         switch(event) {\n            case DIR_CREATED(dir):       trace('Dir created: $dir');\n            case DIR_DELETED(dir):       trace('Dir deleted: $dir');\n            case DIR_MODIFIED(dir, _):   trace('Dir modified: $dir');\n            case FILE_CREATED(file):     trace('File created: $file');\n            case FILE_DELETED(file):     trace('File deleted: $file');\n            case FILE_MODIFIED(file, _): trace('File modified: $file');\n         }\n      });\n\n      fw.watch(\"myconfig.cfg\"); // watch a file\n      fw.watch(\"assets/foo\");   // recursively watch a directory\n\n      // do some file modifications...\n\n      // cleanup\n      fw.stop();\n      ex.stop();\n   }\n}\n```\n\n\n## \u003ca name=\"installation\"\u003e\u003c/a\u003eInstallation\n\n1. install the library via haxelib using the command:\n    ```\n    haxelib install haxe-files\n    ```\n\n2. use in your Haxe project\n\n   * for [OpenFL](http://www.openfl.org/)/[Lime](https://github.com/openfl/lime) projects add `\u003chaxelib name=\"haxe-files\" /\u003e` to your [project.xml](http://www.openfl.org/documentation/projects/project-files/xml-format/)\n   * for free-style projects add `-lib haxe-files`  to `your *.hxml` file or as command line option when running the [Haxe compiler](http://haxe.org/manual/compiler-usage.html)\n\n\n## \u003ca name=\"latest\"\u003e\u003c/a\u003eUsing the latest code\n\n### Using `haxelib git`\n\n```\nhaxelib git haxe-files https://github.com/vegardit/haxe-files main D:\\haxe-projects\\haxe-files\n```\n\n###  Using Git\n\n1. check-out the main branch\n    ```\n    git clone https://github.com/vegardit/haxe-files --branch main --single-branch D:\\haxe-projects\\haxe-files\n    ```\n\n2. register the development release with haxe\n    ```\n    haxelib dev haxe-doctest D:\\haxe-projects\\haxe-files\n    ```\n\n\n## \u003ca name=\"license\"\u003e\u003c/a\u003eLicense\n\nAll files are released under the [Apache License 2.0](LICENSE.txt).\n\nIndividual files contain the following tag instead of the full license text:\n```\nSPDX-License-Identifier: Apache-2.0\n```\n\nThis enables machine processing of license information based on the SPDX License Identifiers that are available here: https://spdx.org/licenses/.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvegardit%2Fhaxe-files","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvegardit%2Fhaxe-files","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvegardit%2Fhaxe-files/lists"}