I have written following code in java for using the DOS copy command through
STAF for copying files:
public boolean bCopy(String astrSourcePath, String astrDesPath)
{
astrSourcePath = astrSourcePath.replace("\\", "\\\\");
astrDesPath = astrDesPath.replace("\\", "\\\\");
//Creating object of STAFHandle
STAFHandle lObjectOfSTAFHandle;
//It is used to create an object of STAFResult which hold output of
STAF command
STAFResult lObjectOfSTAFResult;
try
{
//Creating STAF handle
lObjectOfSTAFHandle = new STAFHandle("CopyFiles");
//Executing the DOS command for copying files
lObjectOfSTAFResult = lObjectOfSTAFHandle.submit2("LOCAL",
"PROCESS", " START Shell COMMAND COPY PARMS \""+
astrSourcePath+"\\\\*.*\" \""+ astrDesPath+"\\\\*.*\" wait
SAMECONSOLE");
//If files are copied successfully
if(lObjectOfSTAFResult.rc == 0)
{
//returning the status of copying files as true
return true;
}
//If files are not copied
else
{
//returning the status of copying files as false
return false;
}
}
catch (STAFException aobjSTAFException)
{
//Printing the exception on consol
aobjSTAFException.printStackTrace();
//returning the status of copying files as false
return false;
}
}
Above method are working fine, if spaces are not exists in the source path
and destination path.
Above method are not working in case of spaces exists in the source path of
destination path.
However after running following STAF command through command prompt, files
are copied in case spaces are exits in source path of destination path:
<Snip>
C:\>STAF LOCAL PROCESS START SHELL COMMAND COPY PARMS \""C:\Documents and
Settings\All Users\Documents\*.*"" \""C:\Documents and Settings\All
Users\Documents\a\
*.*"" wait sameconsole
Response
--------
{
Return Code: 0
Key : <None>
Files : []
}
C:\>
<End>
I have modified the java code with the following code:
public boolean bCopy(String astrSourcePath, String astrDesPath)
{
astrSourcePath = astrSourcePath.replace("\\", "\\\\");
astrDesPath = astrDesPath.replace("\\", "\\\\");
//Creating object of STAFHandle
STAFHandle lObjectOfSTAFHandle;
//It is used to create an object of STAFResult which hold output of
STAF command
STAFResult lObjectOfSTAFResult;
try
{
//Creating STAF handle
lObjectOfSTAFHandle = new STAFHandle("CopyFiles");
//Executing the DOS command for copying files
lObjectOfSTAFResult = lObjectOfSTAFHandle.submit2("LOCAL",
"PROCESS", " START Shell COMMAND COPY PARMS \\\"\""+
astrSourcePath+"\\\\*.*\"\" \\\"\""+ astrDesPath+"\\\\*.*\"\" wait
SAMECONSOLE");
//If files are copied successfully
if(lObjectOfSTAFResult.rc == 0)
{
//returning the status of copying files as true
return true;
}
//If files are not copied
else
{
//returning the status of copying files as false
return false;
}
}
catch (STAFException aobjSTAFException)
{
//Printing the exception on consol
aobjSTAFException.printStackTrace();
//returning the status of copying files as false
return false;
}
}
But still it is not working.
Can anyone tell me what is the problem in the code?
------------------------------------------------------------------------------
_______________________________________________
staf-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/staf-users