Connecting Tech Pros Worldwide Forums | Help | Site Map

IO EXception. copying files in loop

zybernau's Avatar
Member
 
Join Date: Mar 2007
Location: heart of tamil
Posts: 35
#1: Oct 15 '08
hi,
i am trying to copy files in a loop

while copying at some time, IO exception is thrown

zybernau's Avatar
Member
 
Join Date: Mar 2007
Location: heart of tamil
Posts: 35
#2: Oct 15 '08

re: IO EXception. copying files in loop


Quote:

Originally Posted by zybernau

hi,
i am trying to copy files in a loop

while copying at some time, IO exception is thrown

this is the error message thrown
---------------------------
Copy Maestro
---------------------------
File Copy Failed:The process cannot access the file 'C:\Documents and Settings\Admin\Desktop\test grounds\fold1\etst2.dll' because it is being used by another process.
---------------------------
OK
---------------------------

the code,
Expand|Select|Wrap|Line Numbers
  1. foreach (string key in htFilePath.Keys)
  2.  { strFromFile = ((htFilePath[key]) as Filex).FilePathSource;
  3.  strDestFile = ((htFilePath[key]) as Filex).FilePathDest + "\\" + ((htFilePath[key]) as Filex).FileName;
  4.  ResetFileAttribute(strDestFile); File.Copy(strFromFile, strDestFile, true);
  5.  if (blnIncPDB)
  6.  { strFromFile = strFromFile.Replace(".dll", ".pdb");
  7.  strDestFile = strDestFile.Replace(".dll", ".pdb");
  8.  ResetFileAttribute(strDestFile); File.Copy(strFromFile, strDestFile, true); 
  9. } ((htFilePath[key]) as Filex).FileStatus = "Copied"; }
Shashi Sadasivan's Avatar
Moderator
 
Join Date: Aug 2007
Location: Brisbane, Australia
Posts: 1,414
#3: Oct 15 '08

re: IO EXception. copying files in loop


And you are sure that the file is not being read by any other process / application?

If you have also read the file previously before ebtering into the code before, have you closed the stream?
zybernau's Avatar
Member
 
Join Date: Mar 2007
Location: heart of tamil
Posts: 35
#4: Oct 15 '08

re: IO EXception. copying files in loop


Quote:

Originally Posted by Shashi Sadasivan

And you are sure that the file is not being read by any other process / application?

If you have also read the file previously before ebtering into the code before, have you closed the stream?

yes shashi, i sure, i did'nt open that file/ filestream either way.

if i do it one file @ one time it works..
Plater's Avatar
Moderator
 
Join Date: Apr 2007
Location: New England
Posts: 7,161
#5: Oct 15 '08

re: IO EXception. copying files in loop


Quote:

Originally Posted by zybernau

yes shashi, i sure, i did'nt open that file/ filestream either way.

if i do it one file @ one time it works..

Well in your example code you are copy the file twice on some occasions with that IF statement.
It's also possible that the file actually *IS* in use by some other program?
Reply


Similar .NET Framework bytes