1 
  
   2 
  
   3 
  
   4 
  
   5 
  
   6 using System;
  
   7 using System.IO;
  
   8 using System.Collections;
  
   9 using System.Os;
  
  10 
  
  11 bool TargetIsDirectory(const string& target)
  
  12 {
  
  13     byte[statBufSize] statBuf;
  
  14     int result = stat(target.Chars(), &statBuf[0], statBufSize);
  
  15     if (result == -1)
  
  16     {
  
  17         return false;
  
  18     }
  
  19     FileStatus status;
  
  20     GetFileStatus(&statBuf[0], status);
  
  21     return status.fileType == FileType.directory;
  
  22 }
  
  23 
  
  24 void Move(const List<string>& files, const string& target, bool verbose)
  
  25 {
  
  26     if (!TargetIsDirectory(target))
  
  27     {
  
  28         if (files.Count() == 1)
  
  29         {
  
  30             Rename(files.Front().Chars(), target.Chars());
  
  31             if (verbose)
  
  32             {
  
  33                 Console.Out() << files.Front() << " -> " << target << endl();
  
  34             }
  
  35         }
  
  36         else if (files.Count() > 1)
  
  37         {
  
  38             throw Exception("'" + target + "': not directory");
  
  39         }
  
  40     }
  
  41     else
  
  42     {
  
  43         for (const string& file : files)
  
  44         {
  
  45             string name = Path.GetFileName(file);
  
  46             string targetPath = Path.Combine(target, name);
  
  47             Rename(file.Chars(), targetPath.Chars());
  
  48             if (verbose)
  
  49             {
  
  50                 Console.Out() << file << " -> " << targetPath << endl();
  
  51             }
  
  52         }
  
  53     }
  
  54 }