Document handling all file is not moving to folder

I had 4 files in SO folder i need to move all files to Archive/Error folder,

while 1st loop processed 1st file is moving perfectly,

while 2nd loop processed the file is not moving to respective folder its going to catch exception

here is my job:

static void Job44(Args _args)
{
FilePath filePath;
Filename filename;
Filename fileExtension;

FileIOPermission fileIOPerm;
FileIOPermission fileIOPermArchiv;
FileIOPermission fileIOPermError;

SalesTable salesTable;
DocuRef docuRef;
FileName openFileName;
FilePath openFilePath;
FilePath archivingFilePath;
FilePath errorFilePath;

System.IO.DirectoryInfo directory;
System.IO.FileInfo[] files;
System.IO.FileInfo file;

counter filesCount;
counter loop;

int errorlines;
int errorCounter = 1;
str message;

#DEFINE.CurrentVersion(1)
#LOCALMACRO.CurrentList
#ENDMACRO

try
{
archivingFilePath = @‘C:\temp\SalesOrder\Archive’;
errorFilePath = @‘C:\temp\SalesOrder\Error’;

new InteropPermission(InteropKind::ClrInterop).assert();

directory = new System.IO.DirectoryInfo(@‘C:\temp\SalesOrder\SO’);
files = directory.GetFiles();
filesCount = files.get_Length();

for (loop = 0; loop < filesCount; loop++)
{
file = files.GetValue(loop);
openFileName = file.get_FullName();
[filePath, filename, fileExtension] = Global::fileNameSplit(openFileName);

archivingFilePath = strFmt(’%1/%2%3’,archivingFilePath,filename,fileExtension);
errorFilePath = strFmt(’%1/%2%3’,errorFilePath,filename,fileExtension);

if (System.IO.File::Exists(archivingFilePath) ||
System.IO.File::Exists(errorFilePath))
{
continue;
}

// assert file I/O permission
if (isRunningOnServer())
{
fileIOPerm = new FileIOPermission(openFileName,‘rwx’);
fileIOPerm.assert();
fileIOPermArchiv = new FileIOPermission(archivingFilePath,‘rwx’);
fileIOPermArchiv.assert();
fileIOPermError = new FileIOPermission(errorFilePath,‘rwx’);
fileIOPermError.assert();
}

if (SalesTable::exist(filename))
{
System.IO.File::Move(openFileName,archivingFilePath);
}
else
{
System.IO.File::Move(openFileName,errorFilePath);
}
}
}
catch(Exception::Error)
{
throw Exception::Error;
}

}

Any solution for this???

Thanks…

If you need our help with an error, you obviously should tell us what error it is.
You also should have used the debugger to debug your code. Maybe you would be able to fix the problem by yourself, or you could at least tell us which line of your code doesn’t work.

Let me guess: a file can’t be removed because it’s open.

By the way, please ask questions like this in the Developer forum (I’ll move this thread there for you).

Actually no file is open, while debugging the code first loop running and moves the file to archive folder, when loop 2 runs

if (SalesTable::exist(filename)) //checking for file and moving to down

{

System.IO.File::Move(openFileName,archivingFilePath); //while came here i pressed f11 its going to

}

else
{
System.IO.File::Move(openFileName,errorFilePath);
}

}

catch(Exception::Error) //its came here directly
{
throw Exception::Error;
}

I didn’t get any error message, just went to finish stage of process

The problem is with these two lines of code. archivingFilePath and errorFilePath has the old value and you are using the same to build the next file path.

archivingFilePath = @‘C:\temp\SalesOrder\Archive’;
errorFilePath = @‘C:\temp\SalesOrder\Error’;

Bring the above two line inside for loop, (like below)

archivingFilePath = @‘C:\temp\SalesOrder\Archive’;
errorFilePath = @‘C:\temp\SalesOrder\Error’;

archivingFilePath = strFmt(’%1/%2%3’,archivingFilePath,filename,fileExtension);
errorFilePath = strFmt(’%1/%2%3’,errorFilePath,filename,fileExtension);

Thanks Kranthi its working fine now…