Thursday, December 27, 2012

Memindahkan file ke folder lain

static void Test_Move_One_File(Args _args)
{
    System.Exception ex;
    Set permSet = new Set(Types::Class);
    str         errorMsg;
    FileName    _srcFile,_destFile;

;
    _srcFile = "c:\\DATA\\Asal\\copy.txt";
    _destFile = "c:\\DATA\\Tujuan\\copy.txt";

    try
    {
        permSet.add(new FileIOPermission(_srcFile, 'rw'));
        permSet.add(new InteropPermission(InteropKind::ClrInterop));
        permSet.add(new FileIOPermission(_destFile, 'rw'));

        CodeAccessPermission::assertMultiple(permSet);

        if(!System.IO.File::Exists(_srcFile))
        {
            Info("Source file not exist !! Proces terminated.");
            Break;
        }
        else
            {
                Info("Source file exist !! File will be moved.");
                if(System.IO.File::Exists(_destFile))
                {
                   System.IO.File::Delete(_destFile);
                }
            }
        System.IO.File::Move(strfmt(@"%1",_srcFile), strfmt(@"%1",_destFile));
        CodeAccessPermission::revertAssert();
    }

    catch (Exception::CLRError)

    {
        ex = ClrInterop::getLastException();
         if (ex != null)
         {
            ex = ex.get_InnerException();
            if (ex != null)
            {
                error(ex.ToString());
            }
        }
    }

    //return true;
}

No comments:

Post a Comment