CallingPerforming Command Shell functions in webMethods

Are there built-in services to copy, remove, move files in webMethods…akin to using copy or cp, delete or rm, move or mv?

thanks in advance.
KrishnaN

nope!

There is an example of calling a shell command in WmSamples. See commandlineExec example based around
Process child = Runtime.getRuntime().exec(execFile);

There are also examples that include deleteFile in the IO folder of WmSamples.

Krishnan,

The only I have done is using Java services. I am attaching the code for copyFile and you can write the move and delete based on that.

Thanks
Chris


IDataCursor idcPipeline = pipeline.getCursor();

String strFilename = “”;
String strSourceDirectory = null;
String strTargetDirectory = null;

if (idcPipeline.first(“filename”))
{
strFilename = (String)idcPipeline.getValue();
}
else
{
throw new ServiceException(“Copy Failed: Filename is null!”);
}
if (idcPipeline.first(“sourceDirectory”))
{
strSourceDirectory = (String)idcPipeline.getValue();
}
if (idcPipeline.first(“targetDirectory”))
{
strTargetDirectory = (String)idcPipeline.getValue();
}

if (strSourceDirectory != strTargetDirectory)
{

FileReader frSourceFile = null;
FileWriter fwTargetFile = null;
File sourceFile = null;
File targetFile = null;

try
{

sourceFile = new File(strSourceDirectory, strFilename);
targetFile = new File(strTargetDirectory, strFilename);

if (!sourceFile.exists() || sourceFile.isDirectory())

{

throw new ServiceException("MOVE ERROR: Source file not found (" + sourceFile.getAbsolutePath() + ")"); 

}

frSourceFile = new FileReader(sourceFile);
fwTargetFile = new FileWriter(targetFile);

int c;
while ((c = frSourceFile.read()) != -1)
{
fwTargetFile.write(c);
}

idcPipeline.insertAfter(“message”, "Copied: " + sourceFile.getAbsolutePath() + " to " + strTargetDirectory);

}
catch (Exception e)
{
throw new ServiceException(e.getMessage());
}
finally
{
try
{
frSourceFile.close();
fwTargetFile.close();
}
catch (Exception e)
{
}
sourceFile = null;
targetFile = null;
}
}

idcPipeline.destroy();

Krishnan,

Here is the code for Delete…
Basically in Java we have File object which we can use for this purpose.

Thanks
Chris


String strFilename = in.getString(“filename”);

File file;

file = new File(strFilename);

if (!file.exists() || file.isDirectory())

{

out.put(“$error”, “File Delete Error”);

out.put(“$errorMessage”, “File Delete Error: Source file not found (” + file.getAbsolutePath() + “)”);

return out;

}

try

{

file.delete();

file = null;
}

catch (SecurityException e)

{

out.put(“$error”, e.toString());

out.put(“$errorMessage”, e.getMessage());

return out;

}

Create a Batch file in case of Windows or Unix script and execute the script from a Java services

You can download Toolbox package from wmusers.com I have most of these services written in Java directory listing delete, copy etc.

thanks guys…for the bunch of responses. Extremely elated!!

This is off-topic – I just wanted to ask who the “sonam” who made the first response is? It wasn’t me.

Our usernames differ by a capitalization (mine: “Sonam” v/s: “sonam”). Does WMusers.com use authentication cookies? Maybe it’s time further qualify my username.

[ Offtopic again] Er, it could have been me - the question looks familiar. Gee, I looked at it today, and I didn’t think I’d be that abrupt.

Okay, confession time! - Pefectly off-topic too!

That was me who used the name “sonam”. I was being bitchy and irritated when the question popped up in my inbox. It was meant to be silly, not offensive!

Have a wonderful day guys!

Krishnan, One more thing. If you want the code to scan a directory and process a bunch of files at a time, let me know.

Thx

[ Off topic - last time! ]
> That was me who used the name “sonam”. I was being
> bitchy and irritated when the question popped up in my
> inbox. It was meant to be silly, not offensive!

Thanks VR. You really shouldn’t have done it, but you know that already :slight_smile:

Since I remembered reading the question, I began to think that perhaps I had replied and the memory had been repressed (sort of “Dr. Jekyll & Mr. Hyde”) That clears it up. >

Thanks again. .