297 |
298 |
298 |realName| |
299 |realName| |
299 |
300 |
300 (newName = '.') ifFalse:[ |
301 (newName = '.') ifFalse:[ |
301 (newName = '..') ifFalse:[ |
302 (newName = '..') ifFalse:[ |
302 ((newName at:1) == $/) ifTrue:[ |
303 ((newName at:1) == OperatingSystem fileSeparator) ifTrue:[ |
303 realName := newName copyFrom:2 |
304 realName := newName copyFrom:2 |
304 ] ifFalse:[ |
305 ] ifFalse:[ |
305 realName := newName |
306 realName := newName |
306 ]. |
307 ]. |
307 (realName startsWith:'/') ifTrue:[ |
308 ^ OperatingSystem createDirectory:(self class fullPathNameOf:realName in:pathName) |
308 ^ OperatingSystem createDirectory:realName |
|
309 ] ifFalse:[ |
|
310 ^ OperatingSystem createDirectory:(pathName , '/' , realName) |
|
311 ] |
|
312 ] |
309 ] |
313 ]. |
310 ]. |
314 ^ false |
311 ^ false |
315 ! |
312 ! |
316 |
313 |
317 removeFile:fileName |
314 removeFile:fileName |
318 "remove the file 'fileName' from myself; return true if successful" |
315 "remove the file 'fileName' from myself; return true if successful" |
319 |
316 |
320 (fileName startsWith:'/') ifTrue:[ |
317 ^ OperatingSystem removeFile:(self class fullPathNameOf:fileName in:pathName). |
321 ^ OperatingSystem removeFile:fileName |
|
322 ]. |
|
323 ^ OperatingSystem removeFile:(pathName , '/' , fileName) |
|
324 ! |
318 ! |
325 |
319 |
326 removeDirectory:dirName |
320 removeDirectory:dirName |
327 "remove the directory 'dirName' from myself; return true if successful. |
321 "remove the directory 'dirName' from myself; return true if successful. |
328 If the directory is not empty, the containing files/directories are also |
322 If the directory is not empty, the containing files/directories are also |
329 removed." |
323 removed." |
330 |
324 |
331 |absPath| |
325 |path| |
332 |
326 |
333 (dirName startsWith:'/') ifTrue:[ |
327 path := self class fullPathNameOf:dirName in:pathName. |
334 absPath := dirName |
328 (OperatingSystem removeDirectory:path) ifTrue:[^ true]. |
335 ] ifFalse:[ |
329 ^ OperatingSystem recursiveRemoveDirectory:path |
336 absPath := pathName , '/' , dirName |
|
337 ]. |
|
338 (OperatingSystem removeDirectory:absPath) ifTrue:[^ true]. |
|
339 ^ OperatingSystem recursiveRemoveDirectory:absPath |
|
340 ! |
330 ! |
341 |
331 |
342 remove:aFileOrDirectoryName |
332 remove:aFileOrDirectoryName |
343 "remove the file or directory from myself; return true if successful" |
333 "remove the file or directory from myself; return true if successful" |
344 |
334 |
345 |path| |
335 |path| |
346 |
336 |
347 (aFileOrDirectoryName startsWith:'/') ifTrue:[ |
337 path := self class fullPathNameOf:aFileOrDirectoryName in:pathName. |
348 path := aFileOrDirectoryName |
|
349 ] ifFalse:[ |
|
350 path := (pathName , '/' , aFileOrDirectoryName) |
|
351 ]. |
|
352 (OperatingSystem isDirectory:path) ifTrue:[ |
338 (OperatingSystem isDirectory:path) ifTrue:[ |
353 ^ OperatingSystem removeDirectory:path |
339 ^ OperatingSystem removeDirectory:path |
354 ]. |
340 ]. |
355 ^ OperatingSystem removeFile:path |
341 ^ OperatingSystem removeFile:path |
356 ! |
342 ! |
358 link:oldFileName to:newFileName |
344 link:oldFileName to:newFileName |
359 "link oldFileName to newFileName in myself, return true if successful" |
345 "link oldFileName to newFileName in myself, return true if successful" |
360 |
346 |
361 |path1 path2| |
347 |path1 path2| |
362 |
348 |
363 (oldFileName startsWith:'/') ifTrue:[ |
349 path1 := self class fullPathNameOf:oldFileName in:pathName. |
364 path1 := oldFileName |
350 path2 := self class fullPathNameOf:newFileName in:pathName. |
365 ] ifFalse:[ |
|
366 path1 := (pathName , '/' , oldFileName) |
|
367 ]. |
|
368 (newFileName startsWith:'/') ifTrue:[ |
|
369 path2 := newFileName |
|
370 ] ifFalse:[ |
|
371 path2 := (pathName , '/' , newFileName) |
|
372 ]. |
|
373 ^ OperatingSystem linkFile:path1 to:path2 |
351 ^ OperatingSystem linkFile:path1 to:path2 |
374 ! |
352 ! |
375 |
353 |
376 renameFile:oldFileName newName:newFileName |
354 renameFile:oldFileName newName:newFileName |
377 "rename the file; return true if successful" |
355 "rename the file; return true if successful" |
378 |
356 |
379 |path1 path2| |
357 |path1 path2| |
380 |
358 |
381 (oldFileName startsWith:'/') ifTrue:[ |
359 path1 := self class fullPathNameOf:oldFileName in:pathName. |
382 path1 := oldFileName |
360 path2 := self class fullPathNameOf:newFileName in:pathName. |
383 ] ifFalse:[ |
|
384 path1 := (pathName , '/' , oldFileName) |
|
385 ]. |
|
386 (newFileName startsWith:'/') ifTrue:[ |
|
387 path2 := newFileName |
|
388 ] ifFalse:[ |
|
389 path2 := (pathName , '/' , newFileName) |
|
390 ]. |
|
391 ^ OperatingSystem renameFile:path1 to:path2 |
361 ^ OperatingSystem renameFile:path1 to:path2 |
|
362 ! ! |
|
363 |
|
364 !FileDirectory class methodsFor:'private'! |
|
365 |
|
366 fullPathNameOf:name in:path |
|
367 (name startsWith:OperatingSystem fileSeparator) ifTrue:[ |
|
368 ^ name |
|
369 ]. |
|
370 ^ path , OperatingSystem fileSeparator asString , name |
392 ! ! |
371 ! ! |
393 |
372 |
394 !FileDirectory methodsFor:'queries'! |
373 !FileDirectory methodsFor:'queries'! |
395 |
374 |
396 id |
375 id |
418 |
401 |
419 infoOf:name |
402 infoOf:name |
420 "return an array filled with file info for the file 'aFileName'; |
403 "return an array filled with file info for the file 'aFileName'; |
421 return nil if such a file does not exist" |
404 return nil if such a file does not exist" |
422 |
405 |
423 (name startsWith:'/') ifTrue:[ |
406 ^ OperatingSystem infoOf:(self class fullPathNameOf:name in:pathName) |
424 ^ OperatingSystem infoOf:name |
|
425 ]. |
|
426 ^ OperatingSystem infoOf:(pathName , '/' , name) |
|
427 ! |
407 ! |
428 |
408 |
429 timeOfLastChange:name |
409 timeOfLastChange:name |
430 "return the timeStamp of a file in myself" |
410 "return the timeStamp of a file in myself" |
431 |
411 |
432 (name startsWith:'/') ifTrue:[ |
412 ^ OperatingSystem timeOfLastChange:(self class fullPathNameOf:name in:pathName) |
433 ^ OperatingSystem timeOfLastChange:name |
|
434 ]. |
|
435 ^ OperatingSystem timeOfLastChange:(pathName , '/' , name) |
|
436 ! |
413 ! |
437 |
414 |
438 timeOfLastChange |
415 timeOfLastChange |
439 "return the timeStamp of myself" |
416 "return the timeStamp of myself" |
440 |
417 |
441 ^ OperatingSystem timeOfLastChange:pathName |
418 ^ OperatingSystem timeOfLastChange:pathName |
442 ! |
419 ! |
443 |
420 |
444 accessModeOf:aFileName |
421 accessModeOf:name |
445 "return the access-mode bits (rwxrwxrwx) of a file in myself" |
422 "return the access-mode bits (rwxrwxrwx) of a file in myself" |
446 |
423 |
447 (aFileName startsWith:'/') ifTrue:[ |
424 ^ OperatingSystem accessModeOf:(self class fullPathNameOf:name in:pathName) |
448 ^ OperatingSystem accessModeOf:aFileName |
425 ! |
449 ]. |
426 |
450 ^ OperatingSystem accessModeOf:(pathName , '/' , aFileName) |
427 changeAccessModeOf:name to:modeBits |
451 ! |
|
452 |
|
453 changeAccessModeOf:aFileName to:modeBits |
|
454 "set the access-mode bits (rwxrwxrwx) of a file in myself" |
428 "set the access-mode bits (rwxrwxrwx) of a file in myself" |
455 |
429 |
456 (aFileName startsWith:'/') ifTrue:[ |
430 ^ OperatingSystem changeAccessModeOf:(self class fullPathNameOf:name in:pathName) |
457 ^ OperatingSystem changeAccessModeOf:aFileName |
|
458 to:modeBits |
|
459 ]. |
|
460 ^ OperatingSystem changeAccessModeOf:(pathName , '/' , aFileName) |
|
461 to:modeBits |
431 to:modeBits |
462 ! |
432 ! |
463 |
433 |
464 typeOf:aFileName |
434 typeOf:name |
465 "return the symbolic type of a file in myself" |
435 "return the symbolic type of a file in myself" |
466 |
436 |
467 (aFileName startsWith:'/') ifTrue:[ |
437 ^ OperatingSystem typeOf:(self class fullPathNameOf:name in:pathName) |
468 ^ OperatingSystem typeOf:aFileName |
|
469 ]. |
|
470 ^ OperatingSystem typeOf:(pathName , '/' , aFileName) |
|
471 ! |
438 ! |
472 |
439 |
473 exists:name |
440 exists:name |
474 "return true, if the given name exists in myself" |
441 "return true, if the given name exists in myself" |
475 |
442 |
476 (name startsWith:'/') ifTrue:[ |
443 ^ OperatingSystem isValidPath:(self class fullPathNameOf:name in:pathName) |
477 ^ OperatingSystem isValidPath:name |
|
478 ]. |
|
479 ^ OperatingSystem isValidPath:(pathName , '/' , name) |
|
480 ! |
444 ! |
481 |
445 |
482 isDirectory:name |
446 isDirectory:name |
483 "return true, if the given name is that of a directory in myself" |
447 "return true, if the given name is that of a directory in myself" |
484 |
448 |
485 (name startsWith:'/') ifTrue:[ |
449 ^ OperatingSystem isDirectory:(self class fullPathNameOf:name in:pathName) |
486 ^ OperatingSystem isDirectory:name |
|
487 ]. |
|
488 ^ OperatingSystem isDirectory:(pathName , '/' , name) |
|
489 ! |
450 ! |
490 |
451 |
491 isReadable:name |
452 isReadable:name |
492 "return true, if the given file is readable" |
453 "return true, if the given file is readable" |
493 |
454 |
494 (name startsWith:'/') ifTrue:[ |
455 ^ OperatingSystem isReadable:(self class fullPathNameOf:name in:pathName) |
495 ^ OperatingSystem isReadable:name |
|
496 ]. |
|
497 ^ OperatingSystem isReadable:(pathName , '/' , name) |
|
498 ! |
456 ! |
499 |
457 |
500 isWritable:name |
458 isWritable:name |
501 "return true, if the given file is readable" |
459 "return true, if the given file is readable" |
502 |
460 |
503 (name startsWith:'/') ifTrue:[ |
461 ^ OperatingSystem isWritable:(self class fullPathNameOf:name in:pathName) |
504 ^ OperatingSystem isWritable:name |
|
505 ]. |
|
506 ^ OperatingSystem isWritable:(pathName , '/' , name) |
|
507 ! |
462 ! |
508 |
463 |
509 isExecutable:name |
464 isExecutable:name |
510 "return true, if the given file is executable" |
465 "return true, if the given file is executable" |
511 |
466 |
512 (name startsWith:'/') ifTrue:[ |
467 ^ OperatingSystem isExecutable:(self class fullPathNameOf:name in:pathName) |
513 ^ OperatingSystem isExecutable:name |
|
514 ]. |
|
515 ^ OperatingSystem isExecutable:(pathName , '/' , name) |
|
516 ! ! |
468 ! ! |
517 |
469 |
518 !FileDirectory methodsFor:'printing & storing'! |
470 !FileDirectory methodsFor:'printing & storing'! |
519 |
471 |
520 printString |
472 printString |