๐Ÿš€ go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: chile.comp.programacion
Article #634

Re: Eliminacion de Archivos C#

#634
From: Pintamono
Date: Wed, 16 Apr 2008 20:58
60 lines
2957 bytes
Pintamono escribi๏ฟฝ:
> Tengo un problema con la eliminacion de archivos en un directorio 
> especifico.
> 
> Lo hago de la siguiente manera:
> 
> private static void EliminaProcesados() {
> int i;
> string[] strArrFiles;
> string[] strArrDirectory;
> 
> strArrFiles=Directory.GetFiles(PathDirectorioProcesados);
> 
> strArrDirectory=Directory.GetDirectories(PathDirectorioProcesados);
> 
> if(strArrFiles.Length !=0 ||strArrDirectory.Length !=0) {
>  try {
>  if(strArrFiles.Length !=0) {
>   for(i = 0; i <= strArrFiles.GetUpperBound(0); i++) {    FileInfo 
> InfoFile = new FileInfo(strArrFiles[i]);
>     DirectoryInfo InfoDir = new DirectoryInfo(PathDirectorioProcesados);
>     if (InfoDir.Name=="Procesados") {
>      if (InfoFile.Extension.ToLower()==".txt") {
>        if (File.Exists(PathDirectorio+"\\"+InfoFile.Name))
>     File.Delete(PathDirectorio+"\\"+InfoFile.Name);
>        }
>      }
>     }
>   }
>  }
> catch(Exception e) {
>   throw new Exception("Error con el archivo "+e.Message);}
>  }
> }
> 
> El problema que siempre me arroja es este error: "The process cannot 
> access the file [Ruta de mi Archivo] because it is being used by another 
> process"
> 
> Una de las cosas que me di cuenta es que ocurre solo con el ultimo 
> archivo del directorio ya que los primeros los mueve sin problemas.
> 
> Esta malo mi proceso de eliminacion o me falta algo por hacer?
> 
> Gracias.
> 
> PD:
> PathDirectorioProcesados es la ruta de un directorio en done se 
> encuentran los archivos que ya procese
> PathDirectorio es la ruta en donde se encuentran los avisos procesados y 
> sin procesar.

Ya solucione el tema, era porque no cerraba el proceso de lectura del 
archivo...

en algun lugar tenia un StreamReader y no lo cerraba.

eso era todo.

gracias de todas maneras.
Technical Details
Message-ID: <fu5ggd$ih4$1@tucows.gtdinternet.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!fu-berlin.de!news.nivel5.cl!news.gtdinternet.com!not-for-mail
References: <fu5dko$hub$1@tucows.gtdinternet.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: 1593cb,8b9efdff5d7d86c9
X-Google-Attributes: gid1593cb,domainid0,public,usenet
X-Google-Language: SPANISH,ASCII
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!fu-berlin.de!news.nivel5.cl!news.gtdinternet.com!not-for-mail
From: Pintamono <Pintamono@NoMandeWeas.kk>
Newsgroups: chile.comp.programacion
Subject: Re: Eliminacion de Archivos C#
Date: Wed, 16 Apr 2008 16:58:36 -0400
Organization: Gtd Internet S.A.
Lines: 60
Message-ID: <fu5ggd$ih4$1@tucows.gtdinternet.com>
References: <fu5dko$hub$1@tucows.gtdinternet.com>
NNTP-Posting-Host: kerberos.uno.cl
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: tucows.gtdinternet.com 1208370509 18980 200.27.224.101 (16 Apr 2008 18:28:29 GMT)
X-Complaints-To: usenet@gtdinternet.com
NNTP-Posting-Date: Wed, 16 Apr 2008 18:28:29 +0000 (UTC)
User-Agent: Thunderbird 2.0.0.12 (Windows/20080213)
In-Reply-To: <fu5dko$hub$1@tucows.gtdinternet.com>