Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
TXT file doesn´t close
Message
De
22/10/2015 06:43:02
 
 
À
20/10/2015 11:28:24
Information générale
Forum:
ASP.NET
Catégorie:
Autre
Versions des environnements
Environment:
VB.NET 1.1
OS:
Windows 8.1
Network:
Windows 2008 Server
Database:
MS SQL Server
Application:
Desktop
Divers
Thread ID:
01626227
Message ID:
01626315
Vues:
41
First of all you should wrap suh operations in try-catch, as it might fail "reasonably" because somebody has really locked a file in that dir structure. Writing a list of missed files (perhaps resceduling those) is probably the next step - with such a list finding a pattern might be easier.

It is quaranteed that target file is outside drilled dir structure ?


>Hello everyone;
>
>I have a function which makes a merge TXT files ; this go through different folders and taking txt files in each folder is then join the files.
>
>The issue that I have is that after the function makes scanning all folders , the function generates the following eror :
>
>An unhandled exception of type 'System.IO.IOException' occurred in mscorlib.dll
>Additional information: The process cannot access the file 'C:\Users\liderapp\Documents\Scripts\Octubre2015\CM.TXT' because it is being used by another process.
>
>The function is:
>
> For Each topDir As DirectoryInfo In New DirectoryInfo(sourceDir).GetDirectories("*", SearchOption.TopDirectoryOnly)
> For Each subDir As DirectoryInfo In topDir.GetDirectories("*", SearchOption.AllDirectories)
> For Each txtfile As FileInfo In topDir.GetFiles("*.txt", SearchOption.AllDirectories)
> If txtfile.Name.Equals(NameCM, StringComparison.OrdinalIgnoreCase) Then
> curFilename = NameCM
> ElseIf txtfile.Name.Equals(NameGL, StringComparison.OrdinalIgnoreCase) Then
> curFilename = NameGL
> ElseIf txtfile.Name.Equals(NameImp60, StringComparison.OrdinalIgnoreCase) Then
> curFilename = NameImp60
> ElseIf txtfile.Name.Equals(NameImp61, StringComparison.OrdinalIgnoreCase) Then
> curFilename = NameImp61
> ElseIf txtfile.Name.Equals(NameImp62, StringComparison.OrdinalIgnoreCase) Then
> curFilename = NameImp62
> ElseIf txtfile.Name.Equals(NameImp63, StringComparison.OrdinalIgnoreCase) Then
> curFilename = NameImp63
> Else
> curFilename = String.Empty
> End If
> If Not String.IsNullOrEmpty(curFilename) Then
> Debug.WriteLine(topDir.FullName)
> Debug.WriteLine(subDir.FullName)
> Debug.WriteLine(txtfile.FullName)
> Debug.WriteLine(Path.Combine(topDir.FullName, curFilename))
> Using sr As StreamReader = txtfile.OpenText
> File.AppendAllText(Path.Combine(topDir.FullName, curFilename), sr.ReadToEnd, Encoding.Default)
> End Using
> End If
> Next txtfile
> Next subDir
> Next topDir
>
>The issue happen when the scaning process finish and occur in this sentences:
>File.AppendAllText(Path.Combine(topDir.FullName, curFilename), sr.ReadToEnd, Encoding.Default)
>
>How I can avoid the error ?
>
>TIA
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform