Sebelumnya, pastikan sudah dapat hak akses untuk bisa hapus folder dan file tersebut
static void Test_Move_One_File(Args _args)
{
System.Exception ex;
Set permSet = new Set(Types::Class);
str errorMsg;
FileName _srcFile,_destFile;
;
_srcFile = "D:\\Move_Src\\File.txt";
_destFile = "D:\\Move_Dst\\File.txt";
try
{
permSet.add(new FileIOPermission(_srcFile, 'rw'));
permSet.add(new InteropPermission(InteropKind::ClrInterop));
permSet.add(new FileIOPermission(_destFile, 'rw'));
CodeAccessPermission::assertMultiple(permSet);
//Kalo file sumber tidak ada, maka batalkan proses
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());
}
}
}
}
Friday, June 8, 2012
List nama-nama file dalam folder
static void Test_ListDirFiles(Args _args)
{
FilePath filePath = "d:\\Documents\\Project";
FileNameFilter fileFilter = ["*.*", "All files"];
FileName fileName;
int fileHandle;
;
// Get first file in directory
[fileHandle, fileName] = WinAPI::findFirstFile(strFmt("%1\\%2", filePath, conPeek(fileFilter, 1)));
// While files found
while(fileName)
{
// ------------------------------------------
// Filepath and filename are known here...
// ------------------------------------------
info(strFmt("%1%2", filePath, fileName));
// Get next file
fileName = winAPI::findNextFile(fileHandle);
}
}
{
FilePath filePath = "d:\\Documents\\Project";
FileNameFilter fileFilter = ["*.*", "All files"];
FileName fileName;
int fileHandle;
;
// Get first file in directory
[fileHandle, fileName] = WinAPI::findFirstFile(strFmt("%1\\%2", filePath, conPeek(fileFilter, 1)));
// While files found
while(fileName)
{
// ------------------------------------------
// Filepath and filename are known here...
// ------------------------------------------
info(strFmt("%1%2", filePath, fileName));
// Get next file
fileName = winAPI::findNextFile(fileHandle);
}
}
Subscribe to:
Posts (Atom)