File oFile;
int iReaded;
String sFullPath;
boolean bRetVal = false;
boolean bFTPSession = false;
FTPClient oFTPC = null;
String sCmd = null;
InputStream oStdOut;
byte verbose[] = new byte[256];
if (DebugFile.trace) {
DebugFile.writeln("Begin FileSystem.rmdir(" + sFullURI + ")");
DebugFile.incIdent();
}
if (sFullURI.startsWith("file://")) {
sFullPath = sFullURI.substring(7);
if (sFullPath.endsWith(SLASH)) sFullPath = sFullPath.substring(0, sFullPath.length()-SLASH.length());
oFile = new File(sFullPath);
if (DebugFile.trace) DebugFile.writeln(sFullPath + " is a directory");
switch (OS) {
case OS_PUREJAVA:
bRetVal = oFile.delete();
break;
case OS_UNIX:
sCmd = "rm -rf \"" + sFullPath + "\"";
break;
case OS_WINDOWS:
sCmd = "DEL /F /S /Q \"" + sFullPath + "\"";
break;
} // end switch()
if (null!=sCmd) {
if (DebugFile.trace) {
DebugFile.writeln("Runtime.exec(" + sCmd + ")");
oStdOut = oRunner.exec(sCmd).getInputStream();
iReaded = oStdOut.read(verbose, 0, 255);
oStdOut.close();
if (iReaded > 0) {
DebugFile.writeln(new String(verbose, iReaded));
bRetVal = false;
}
else
bRetVal = true;
}
else {
oRunner.exec(sCmd);
bRetVal = true;
}
} // fi (sCmd)
if (oFile.exists()) bRetVal = false;
oFile = null;
}
else if (sFullURI.startsWith("ftp://")) {
splitURI(sFullURI);
try {
if (DebugFile.trace) DebugFile.writeln("new FTPClient(" + sHost + ")");
oFTPC = new FTPClient(sHost);
if (DebugFile.trace) DebugFile.writeln("oFTPC.login(" + sUsr + ", ...);");
oFTPC.login(sUsr, sPwd);
bFTPSession = true;
sFullPath = Gadgets.chomp(sPath, '/') + sFile;
String[] aSubDirs = listDirsFTP(oFTPC, sFullPath);
for (int d = 0; d < aSubDirs.length; d++) {
delete (Gadgets.chomp(sFullURI, '/') + aSubDirs[d]);
}
String[] aFiles = listFilesFTP(oFTPC, sFullPath);
for (int f=0; f<aFiles.length; f++) {
if (DebugFile.trace) DebugFile.writeln("FTPClient.delete(" + Gadgets.chomp(sPath,'/') + Gadgets.chomp(sFile,'/') + aFiles[f] + ")");
oFTPC.delete (Gadgets.chomp(sPath,'/') + Gadgets.chomp(sFile,'/') + aFiles[f]);
}
if (DebugFile.trace) DebugFile.writeln("FTPClient.rmdir(" + sFullPath + ")");
oFTPC.rmdir(sFullPath);
bRetVal = true;
} catch (FTPException ftpe) {
bRetVal = false;
throw new IOException(ftpe.getMessage());
}
catch (Exception xcpt) {
bRetVal = false;
throw new IOException(xcpt.getMessage());
}
finally {
try { if (bFTPSession) oFTPC.quit(); } catch (Exception xcpt) { }
}
}
// fi(sFullURI.startsWith(...))
if (DebugFile.trace) {