-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFileUtility.ms
More file actions
737 lines (685 loc) · 25.4 KB
/
FileUtility.ms
File metadata and controls
737 lines (685 loc) · 25.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
/*! © 2022 imaoki | MIT License | https://github.com/imaoki */
/*-
一般的なファイルおよびディレクトリの操作に加えてスクリプトファイルやシーンファイルの操作を行うメソッドも提供する。
@remarks エンコーディングは指定がない限りUTF-8(BOM無し)を使用する。
*/
struct FileUtilityStruct (
/*- @prop <Struct:ComparerStruct> */
private comparer,
/*- @prop <DotNetClass:System.IO.Directory> */
private directoryClass = DotNetClass "System.IO.Directory",
/*- @prop <DotNetClass:System.IO.DirectoryInfo> */
private directoryInfoClass = DotNetClass "System.IO.DirectoryInfo",
/*- @prop <Struct:DotNetUtilityStruct> */
private dotNetUtility,
/*- @prop <StructDef:EncodingStruct> */
private encodingDef,
/*- @prop <StructDef:EnumStruct> */
private enumDef,
/*- @prop <Struct:EnumStruct> `"System.IO.FileAttributes"`列挙型。 */
private fileAttributesEnum,
/*- @prop <DotNetClass:System.IO.File> */
private fileClass = DotNetClass "System.IO.File",
/*- @prop <Struct:PathUtilityStruct> */
private pathUtility,
/*- @prop <StructDef:PathUtilityStruct> */
private pathUtilityDef,
/*- @prop <Struct:EnumStruct> `"System.IO.SearchOption"`列挙型。 */
private searchOptionEnum,
/*
public fn CopyDirectory source destination overwrite:false = (),
public fn CopyFile source destination overwrite:false = (),
public fn CreateDirectory path = (),
public fn CreateTextFile path access:#Write encoding:"utf-8" bom:false = (),
public fn DeleteDirectory path recursive:true = (),
public fn DeleteFile path = (),
public fn DirectoryExists path = (),
public fn EvaluateFile path = (),
public fn FileExists path = (),
public fn GetCreationTime path asUtc:false = (),
public fn GetDirectories path pattern recursive:false = (),
public fn GetFiles path pattern recursive:false = (),
public fn GetLastAccessTime path asUtc:false = (),
public fn GetLastWriteTime path asUtc:false = (),
public fn GetMaxVersion path = (),
public fn IsHidden path = (),
public fn IsMaxFile path = (),
public fn IsReadOnly path = (),
public fn IsScriptFile path = (),
public fn MoveDirectory source destination = (),
public fn OpenTextFile path access:#Read encoding:"utf-8" bom:false = (),
public fn ReadAllLines path encoding:"utf-8" bom:false = (),
public fn ReadAllText path encoding:"utf-8" bom:false = (),
public fn RenameDirectory path newName = (),
public fn RenameFile path newName = (),
public fn WriteAllLines path contents eol:"\n" encoding:"utf-8" bom:false = (),
public fn WriteAllText path contents encoding:"utf-8" bom:false = (),
private fn copyDirectoryRecursive source destination overwrite = (),
private fn createDirectoryInfo path = (),
private fn createEncoding encoding bom = (),
private fn createSearchOption recursive = (),
private fn getAttributes path = (),
private fn getPathType path = (),
private fn isFileAttributesObject obj = (),
*/
/*-
ディレクトリをコピーする。
@param source <String> コピーするディレクトリのパス。
@param destination <String> コピー先のパス。
@param overwrite: <BooleanClass> 上書きする場合は`true`、それ以外の場合は`false`。既定値は`false`。
@returns <OkClass>
*/
public fn CopyDirectory source destination overwrite:false = (
if this.DirectoryExists source and classOf destination == String do (
destination = this.pathUtility.TrimEndSeparator destination
this.copyDirectoryRecursive source destination overwrite
)
ok
),
/*-
ファイルをコピーする。
@param source <String> コピーするファイルのパス。
@param destination <String> コピー先のパス。
@param overwrite: <BooleanClass> 上書きする場合は`true`、それ以外の場合は`false`。既定値は`false`。
@returns <OkClass>
*/
public fn CopyFile source destination overwrite:false = (
if this.FileExists source and classOf destination == String do (
if overwrite or not this.FileExists destination do (
this.fileClass.Copy source destination overwrite
)
)
ok
),
/*-
指定されたパスに全てのディレクトリとサブディレクトリを作成する。
@param path <String>
@returns <DotNetObject:System.IO.DirectoryInfo>
*/
public fn CreateDirectory path = (
this.directoryClass.CreateDirectory path
),
/*-
テキストファイルを作成、または上書きする。
@param path <String>
@param access: <Name> 実行可能な操作。既定値は`#Write`。
@param encoding: <String> エンコーディングの名前。既定値は`"utf-8"`。
@param bom: <BooleanClass> BOMの有無。既定値は`false`。
@returns <FileStream|UndefinedClass> MAXScriptの`FileStream`値。
@remarks 指定可能な値は`OpenTextFile`を参照。
*/
public fn CreateTextFile path access:#Write encoding:"utf-8" bom:false = (
local fs = this.fileClass.Create path
if this.dotNetUtility.IsInstanceOf "System.IO.FileStream" fs do (
fs.Close()
)
this.OpenTextFile path access:access encoding:encoding bom:bom
),
/*-
ディレクトリを削除する。
@param path <String>
@param recursive: <BooleanClass> サブディレクトリ、およびファイルを削除する場合は`true`、それ以外の場合は`false`。既定値は`true`。
@returns <OkClass>
@remarks
`recursive`が`false`の時、指定されたディレクトリが空でない場合は削除しない。
ゴミ箱には移動しないので使用の際は注意すること。
*/
public fn DeleteDirectory path recursive:true = (
if this.DirectoryExists path do (
local subDirs = this.directoryClass.GetDirectories path
local subFiles = this.directoryClass.GetFiles path
if recursive or (subDirs.Count == 0 and subFiles.Count == 0) do (
this.directoryClass.Delete path recursive
)
)
),
/*-
ファイルを削除する。
@param path <String>
@returns <OkClass>
@remarks ゴミ箱には移動しないので使用の際は注意すること。
*/
public fn DeleteFile path = (
if this.FileExists path do (
this.fileClass.Delete path
)
ok
),
/*-
ディレクトリが存在するかどうかを判定する。
@param path <String>
@returns <BooleanClass>
*/
public fn DirectoryExists path = (
this.directoryClass.Exists path
),
/*-
MAXScriptファイルを評価する。
@param path <String>
@returns <Any|UndefinedClass> msファイルでない場合は`undefined`を返す。
@remarks msファイルのみが対象。
*/
public fn EvaluateFile path = (
if this.IsScriptFile path then (
fileIn path
)
else (
undefined
)
),
/*-
ファイルが存在するかどうかを判定する。
@param path <String>
@returns <BooleanClass>
*/
public fn FileExists path = (
this.fileClass.Exists path
),
/*-
ディレクトリまたはファイルの作成日時を取得する。
@param path <String>
@param asUtc: <BooleanClass> 世界協定時刻(UTC)で取得する場合は`true`、現在時刻で取得する場合は`false`。既定値は`false`。
@returns <DotNetObject:System.DateTime>
*/
public fn GetCreationTime path asUtc:false = (
local dateTimeObject = undefined
case this.getPathType path of (
(#Directory): (
if asUtc then (
dateTimeObject = this.directoryClass.GetCreationTimeUtc path
)
else (
dateTimeObject = this.directoryClass.GetCreationTime path
)
)
(#File): (
if asUtc then (
dateTimeObject = this.fileClass.GetCreationTimeUtc path
)
else (
dateTimeObject = this.fileClass.GetCreationTime path
)
)
default: ()
)
dateTimeObject
),
/*-
パターンに一致したサブディレクトリを取得する。
@param path <String>
@param pattern <String> リテラル文字とワイルドカード文字の組み合わせ。大文字と小文字を区別しない。
@param recursive: <BooleanClass> 全てのサブディレクトリから検索する場合は`true`、現在のディレクトリからのみ検索する場合は`false`。既定値は`false`。
@returns <Array[<Struct:Path>]>
@remarks
パスは自然順にソートされる。
パターン照合は`"*"`で全てのサブディレクトリを取得した後、`matchPattern`関数によって照合される。
よってパスの中間部分で選別する場合はパターン文字列の前後にワイルドカードが必要となる点に注意する。
| 基点 | 取得したいパス | 検索パターン |
| --------------- | ------------------------- | ------------ |
| `@"C:\Foo\Bar"` | `@"C:\Foo\Bar\Hoge\Piyo"` | `"*\Hoge*"` |
*/
public fn GetDirectories path pattern recursive:false = (
local option = this.createSearchOption recursive
local dirs = this.directoryClass.GetDirectories path "*" option
qsort dirs this.comparer.CompareStringLogical
for dir in dirs collect (
if matchPattern dir pattern:pattern ignoreCase:true then (
dir
)
else (
dontCollect
)
)
),
/*-
パターンに一致したファイルを取得する。
@param path <String>
@param pattern <String> リテラル文字とワイルドカード文字の組み合わせ。大文字と小文字を区別しない。
@param recursive: <BooleanClass> 全てのサブディレクトリから検索する場合は`true`、現在のディレクトリからのみ検索する場合は`false`。既定値は`false`。
@returns <Array[<Struct:Path>]>
@remarks
パスは自然順にソートされる。
パターン照合は`"*"`で全てのサブディレクトリを取得した後、`matchPattern`関数によって照合される。
よってパスの中間部分で選別する場合はパターン文字列の前後にワイルドカードが必要となる点に注意する。
| 基点 | 取得したいパス | 検索パターン |
| --------------- | ----------------------------- | --------------- |
| `@"C:\Foo\Bar"` | `@"C:\Foo\Bar\Hoge\Piyo.txt"` | `"*\Hoge*.txt"` |
*/
public fn GetFiles path pattern recursive:false = (
local option = this.createSearchOption recursive
local files = this.directoryClass.GetFiles path "*" option
qsort files this.comparer.CompareStringLogical
for file in files collect (
if matchPattern file pattern:pattern ignoreCase:true then (
file
)
else (
dontCollect
)
)
),
/*-
ディレクトリまたはファイルの最終アクセス日時を取得する。
@param path <String>
@param asUtc: <BooleanClass> 世界協定時刻(UTC)で取得する場合は`true`、現在時刻で取得する場合は`false`。既定値は`false`。
@returns <DotNetObject:System.DateTime>
*/
public fn GetLastAccessTime path asUtc:false = (
local dateTimeObject = undefined
case this.getPathType path of (
(#Directory): (
if asUtc then (
dateTimeObject = this.directoryClass.GetLastAccessTimeUtc path
)
else (
dateTimeObject = this.directoryClass.GetLastAccessTime path
)
)
(#File): (
if asUtc then (
dateTimeObject = this.fileClass.GetLastAccessTimeUtc path
)
else (
dateTimeObject = this.fileClass.GetLastAccessTime path
)
)
default: ()
)
dateTimeObject
),
/*-
ディレクトリまたはファイルの最終書き込み日時を取得する。
@param path <String>
@param asUtc: <BooleanClass> 世界協定時刻(UTC)で取得する場合は`true`、現在時刻で取得する場合は`false`。既定値は`false`。
@returns <DotNetObject:System.DateTime>
*/
public fn GetLastWriteTime path asUtc:false = (
local dateTimeObject = undefined
case this.getPathType path of (
(#Directory): (
if asUtc then (
dateTimeObject = this.directoryClass.GetLastWriteTimeUtc path
)
else (
dateTimeObject = this.directoryClass.GetLastWriteTime path
)
)
(#File): (
if asUtc then (
dateTimeObject = this.fileClass.GetLastWriteTimeUtc path
)
else (
dateTimeObject = this.fileClass.GetLastWriteTime path
)
)
default: ()
)
dateTimeObject
),
/*-
Maxシーンファイルのバージョンを西暦形式の整数で取得する。
@param path <String>
@returns <Integer>
@remarks
ファイルが存在しない等でバージョンが取得できない場合は`0`を返す。
3ds Max 9以前のバージョンについても一律西暦形式で扱う。
*/
public fn GetMaxVersion path = (
local version = 0
if this.IsMaxFile path do (
version = (getMaxFileVersionData path)[1] / 1000 + 1998
)
version
),
/*-
ディレクトリまたはファイルが隠し属性かどうかを判定する。
@param path <String>
@returns <BooleanClass>
*/
public fn IsHidden path = (
local attributesObject = this.getAttributes path
this.isFileAttributesObject attributesObject \
and this.fileAttributesEnum.HasFlag attributesObject #Hidden
),
/*-
ファイルがMaxシーンファイルかどうかを判定する。
@param path <String>
@returns <BooleanClass>
*/
public fn IsMaxFile path = (
this.FileExists path and ::isMaxFile path
),
/*-
ディレクトリまたはファイルが読み取り専用かどうかを判定する。
@param path <String>
@returns <BooleanClass>
@remarks
Windowsのディレクトリを読み取り専用に設定するためにはPowerShell等を利用する必要がある。
```powershell
Set-ItemProperty -Path .\foo -Name Attributes -Value "ReadOnly"
```
```dos
attrib foo +R
```
*/
public fn IsReadOnly path = (
local attributesObject = this.getAttributes path
this.isFileAttributesObject attributesObject \
and this.fileAttributesEnum.HasFlag attributesObject #ReadOnly
),
/*-
ファイルがスクリプトファイルかどうかを判定する。
@param path <String>
@returns <BooleanClass>
@remarks msファイルのみが対象。
*/
public fn IsScriptFile path = (
local extension = this.pathUtility.GetExtension path
this.FileExists path and stricmp extension ".ms" == 0
),
/*-
ディレクトリまたはファイルのディレクトリ部分を変更する。
@param source <String> ディレクトリまたはファイルのパス。
@param destination <String> 移動先のディレクトリまたはファイルのパス。ファイルパスを指定した場合はディレクトリ部分が使用される。
@returns <OkClass>
*/
public fn MoveDirectory source destination = (
destination = this.pathUtility.TrimEndSeparator destination
if this.DirectoryExists destination do (
destination += @"\" + (this.pathUtility.GetFileName source)
case this.getPathType source of (
(#Directory): this.directoryClass.Move source destination
(#File): this.fileClass.Move source destination
default: ()
)
)
ok
),
/*-
テキストファイルを開く。
@param path <String>
@param access: <Name> 実行可能な操作を以下の値で指定する。既定値は`#Read`。
| 値 | 操作 | `openFile`関数の`mode`パラメータの対応 |
| ------------ | ----------------- | -------------------------------------- |
| `#Read` | 読み取り | `"rt"` |
| `#ReadWrite` | 読み取り/書き込み | `"r+"` |
| `#Write` | 書き込み | `"wt"` |
これ以外の値を指定した場合は`#Read`が使用される。
@param encoding: <String> エンコーディングの名前。既定値は`"utf-8"`。
@param bom: <BooleanClass> BOMの有無。既定値は`false`。
@returns <FileStream|UndefinedClass> MAXScriptの`FileStream`値。
*/
public fn OpenTextFile path access:#Read encoding:"utf-8" bom:false = (
local fs = undefined
if this.FileExists path do (
local modeValue = case access of (
(#ReadWrite): "r+"
(#Write): "wt"
default: "rt"
)
local encodingObject = this.createEncoding encoding bom
local codePage = encodingObject.GetCodePage()
fs = openFile path mode:modeValue encoding:codePage writeBOM:bom
)
fs
),
/*-
ファイルの全ての行を読み取る。
@param path <String>
@param encoding: <String> エンコーディングの名前。既定値は`"utf-8"`。
@param bom: <BooleanClass> BOMの有無。既定値は`false`。
@returns <Array[<String>]|UndefinedClass> ファイルが存在しない場合は`undefined`を返す。
*/
public fn ReadAllLines path encoding:"utf-8" bom:false = (
local contents = undefined
if this.FileExists path do (
local encodingObject = this.createEncoding encoding bom
contents = this.fileClass.ReadAllLines path (encodingObject.GetEncodingObject())
)
contents
),
/*-
ファイルの全てのテキストを読み取る。
@param path <String>
@param encoding: <String> エンコーディングの名前。既定値は`"utf-8"`。
@param bom: <BooleanClass> BOMの有無。既定値は`false`。
@returns <String|UndefinedClass> ファイルが存在しない場合は`undefined`を返す。
*/
public fn ReadAllText path encoding:"utf-8" bom:false = (
local contents = undefined
if this.FileExists path do (
local encodingObject = this.createEncoding encoding bom
contents = this.fileClass.ReadAllText path (encodingObject.GetEncodingObject())
)
contents
),
/*-
ディレクトリ名を変更する。
@param path <String>
@param newName <String> 新しいディレクトリ名。
@returns <OkClass>
*/
public fn RenameDirectory path newName = (
if this.DirectoryExists path and classOf newName == String do (
local dir = this.pathUtility.GetDirectoryName path
if classOf dir == String and this.DirectoryExists dir do (
newName = this.pathUtility.GetFileNameWithoutExtension newName
local destination = dir + @"\" + newName
if not this.DirectoryExists destination do (
this.directoryClass.Move path destination
)
)
)
ok
),
/*-
ファイル名を変更する。
@param path <String>
@param newName <String> 新しいファイル名。
@returns <OkClass>
@remarks 拡張子が含まれている場合は全て変更し、含まれていない場合は拡張子を引き継ぐ。
*/
public fn RenameFile path newName = (
if this.FileExists path and classOf newName == String do (
local dir = this.pathUtility.GetDirectoryName path
if classOf dir == String and this.DirectoryExists dir do (
local destination = dir + @"\" + newName
if not this.pathUtility.HasExtension destination do (
destination += this.pathUtility.GetExtension path
)
if not this.FileExists destination do (
this.fileClass.Move path destination
)
)
)
ok
),
/*-
ファイルを作成して行を書き込む。
@param path <String>
@param contents <Array[<Any>]>
@param eol: <String> 改行コード。既定値は`"\n"`。
@param encoding: <String> エンコーディングの名前。既定値は`"utf-8"`。
@param bom: <BooleanClass> BOMの有無。既定値は`false`。
@returns <OkClass>
@remarks
既存のファイルは上書きされる。
ディレクトリが存在しない場合は作成に失敗する。
*/
public fn WriteAllLines path contents eol:"\n" encoding:"utf-8" bom:false = (
local ss = StringStream ""
if classOf contents == Array do (
with printAllElements true (
for content in contents do (
format "%%" content eol to:ss
)
)
)
this.WriteAllText path ss encoding:encoding bom:bom
ok
),
/*-
ファイルを作成して文字列を書き込む。
@param path <String>
@param contents <String|StringStream>
@param encoding: <String> エンコーディングの名前。既定値は`"utf-8"`。
@param bom: <BooleanClass> BOMの有無。既定値は`false`。
@returns <OkClass>
@remarks
既存のファイルは上書きされる。
ディレクトリが存在しない場合は作成に失敗する。
*/
public fn WriteAllText path contents encoding:"utf-8" bom:false = (
if this.DirectoryExists (this.pathUtility.GetDirectoryName path) do (
contents = contents as String
local encodingObject = this.createEncoding encoding bom
this.fileClass.WriteAllText path contents (encodingObject.GetEncodingObject())
)
ok
),
/*-
ディレクトリを再帰的にコピーする。
@param source <String> コピーするディレクトリのパス。
@param destination <String> コピー先パス。
@param overwrite <BooleanClass>
@returns <OkClass>
*/
private fn copyDirectoryRecursive source destination overwrite = (
if not this.DirectoryExists destination do (
local sourceInfo = this.createDirectoryInfo source
local destinationInfo = this.CreateDirectory destination
destinationInfo.Attributes = sourceInfo.Attributes
)
if this.DirectoryExists destination do (
local files = this.directoryClass.GetFiles source
for subSource in files do (
local subDestination = copy destination
subDestination += @"\" + (this.pathUtility.GetFileName subSource)
this.CopyFile subSource subDestination overwrite:overwrite
)
local dirs = this.directoryClass.GetDirectories source
for subSource in dirs do (
local subDestination = copy destination
subDestination += @"\" + (this.pathUtility.GetFileName subSource)
this.copyDirectoryRecursive subSource subDestination overwrite
)
)
ok
),
/*-
`"System.IO.DirectoryInfo"`オブジェクトを生成する。
@param path <String>
@returns <DotNetObject:System.IO.DirectoryInfo>
*/
private fn createDirectoryInfo path = (
DotNetObject this.directoryInfoClass path
),
/*-
エンコーディングオブジェクトを生成する。
@param encoding <String>
@param bom <BooleanClass>
@returns <Struct:Encoding>
*/
private fn createEncoding encoding bom = (
local encodingObject = this.encodingDef encoding bom
if not encodingObject.IsValidEncoding() do (
encodingObject = this.encodingDef()
)
encodingObject
),
/*-
`"System.IO.SearchOption"`オブジェクトを生成する。
@param recursive <BooleanClass>
@returns <DotNetObject:System.IO.SearchOption>
*/
private fn createSearchOption recursive = (
if recursive then (
this.searchOptionEnum.Create #(#AllDirectories)
)
else (
this.searchOptionEnum.Create #(#TopDirectoryOnly)
)
),
/*-
ディレクトリまたはファイルの`FileAttributes`オブジェクトを取得する。
@param path <String>
@returns <DotNetObject:System.IO.FileAttributes>
*/
private fn getAttributes path = (
local attributesObject = undefined
case this.getPathType path of (
(#Directory): (
attributesObject = (this.createDirectoryInfo path).Attributes
)
(#File): (
attributesObject = this.fileClass.GetAttributes path
)
default: ()
)
attributesObject
),
/*-
パスの種類を判定する。
@param path <String>
@returns <Name>
| 種類 | 値 |
| ------------ | ------------ |
| ディレクトリ | `#Directory` |
| ファイル | `#File` |
| 不明 | `#Unknown` |
*/
private fn getPathType path = (
if this.FileExists path then (
#File
)
else (
if this.DirectoryExists path then (
#Directory
)
else (
#Unknown
)
)
),
/*-
@param obj <Any>
@returns <BooleanClass>
*/
private fn isFileAttributesObject obj = (
this.dotNetUtility.IsInstanceOf "System.IO.FileAttributes" obj
),
/*- @returns <Name> */
public fn StructName = #FileUtilityStruct,
/*-
@param indent: <String>
@param out: <FileStream|StringStream|WindowStream> 出力先。既定値は`listener`。
@returns <OkClass>
*/
public fn Dump indent:"" out:listener = (
format "%FileUtilityStruct\n" indent to:out
ok
),
/*-
@param obj <Any>
@returns <BooleanClass>
@remarks 大文字と小文字を区別する。
*/
public fn Equals obj = (
local isEqualStructName = isStruct obj \
and isProperty obj #StructName \
and classOf obj.StructName == MAXScriptFunction \
and obj.StructName() == this.StructName()
local isEqualProperties = true
isEqualStructName and isEqualProperties
),
on Create do (
this.comparer = (::standardDefinitionPool[@"Comparer.ms"])()
this.dotNetUtility = (::standardDefinitionPool[@"DotNetUtility.ms"])()
this.encodingDef = ::standardDefinitionPool[@"Encoding.ms"]
this.enumDef = ::standardDefinitionPool[@"Enum.ms"]
this.pathUtilityDef = ::standardDefinitionPool[@"PathUtility.ms"]
this.pathUtility = this.pathUtilityDef (getSourceFileName())
this.fileAttributesEnum = this.enumDef "System.IO.FileAttributes"
this.searchOptionEnum = this.enumDef "System.IO.SearchOption"
)
)