FileSystem.hx 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /*
  2. * Copyright (C)2005-2012 Haxe Foundation
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a
  5. * copy of this software and associated documentation files (the "Software"),
  6. * to deal in the Software without restriction, including without limitation
  7. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  8. * and/or sell copies of the Software, and to permit persons to whom the
  9. * Software is furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice shall be included in
  12. * all copies or substantial portions of the Software.
  13. *
  14. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  20. * DEALINGS IN THE SOFTWARE.
  21. */
  22. package sys;
  23. import python.lib.Os;
  24. import python.lib.os.Path;
  25. @:coreApi
  26. class FileSystem {
  27. public static function exists( path : String ) : Bool {
  28. return Path.exists(path);
  29. }
  30. public static function stat( path : String ) : sys.FileStat {
  31. var s = Os.stat(path);
  32. return {
  33. gid : s.st_gid,
  34. uid : s.st_uid,
  35. atime : Date.fromTime(s.st_atime),
  36. mtime : Date.fromTime(s.st_mtime),
  37. ctime : Date.fromTime(s.st_ctime),
  38. size : s.st_size,
  39. dev : s.st_dev,
  40. ino : s.st_ino,
  41. nlink : s.st_nlink,
  42. rdev : s.st_rdev,
  43. mode : s.st_mode
  44. }
  45. }
  46. public static function rename( path : String, newPath : String ) : Void {
  47. Os.rename(path, newPath);
  48. }
  49. public static function fullPath( relPath : String ) : String {
  50. return Path.abspath(relPath);
  51. }
  52. public static function isDirectory( path : String ) : Bool
  53. {
  54. return Path.isdir(path);
  55. }
  56. public static function createDirectory( path : String ) : Void
  57. {
  58. Os.mkdir(path);
  59. }
  60. public static function deleteFile( path : String ) : Void
  61. {
  62. Os.remove(path);
  63. }
  64. public static function deleteDirectory( path : String ) : Void
  65. {
  66. Os.rmdir(path);
  67. }
  68. public static function readDirectory( path : String ) : Array<String>
  69. {
  70. return Os.listdir(path);
  71. }
  72. }