Home All Groups Group Topic Archive Search About

Aaargh!! Renaming file issues

Author
4 Dec 2006 3:35 AM
bulldog8
I've read numerous posts and have tried multiple approaches that I
found, but just cannot get a file renamed.  I am using VB.Net 2002 ...

Here is what I have tried:

1) Code common to all attempts:

OldName = "c:\albums\061203\email\DSC07272.JPG"
NewName = "c:\albums\061203\email\Lalala.JPG"

sNewFileCheck = Dir(NewName)

If sNewFileCheck = "" Then
    ... followed by the below

a) ReName(OldFile, NewFile)
    Error 53 : File not found
                 I am assuming it cannot find the old file here ...

b) System.IO.File.Move
    Error 57
    "The process cannot access the file
"c:\albums\061203\email\Lalala.JPG" because it is being used by another
process."

                - Very confusing, since Lalala.jpg did not exist prior
to the Move call

c) System.IO.File.Copy(OldFile, NewFile) works,
    Kill(OldFile)   fails with
    Error 55
    "The process cannot access the file
"c:\albums\061203\email\DSC07272.JPG" because it is being used by
another process."
     - Confusing also, since in debug I go and verify that the new file
has been created.  Maybe adding a DoEvents before Kill?


I wish VB was still simple and BASIC .....

Any direction would be appreciated!

- Jon

Author
4 Dec 2006 4:33 AM
Newbie Coder
Imports System.IO

    Private Sub RenameFile(ByVal sOldFile As String, ByVal sNewFile As
String)
        If File.Exists(sOldFile) = True Then
            File.Move(sOldFile, sNewFile)
        Else
            MessageBox.Show("File to be renamed doesn't exist", "Rename
Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
        End If
    End Sub

Usage:

RenameFile("C:\Test1.txt", "C:\Test2.txt")
-------------------------------------------------------

It sounds like your code failed trying to move the file therefor it kept the
file locked open. This would explain why the file is being used by another
process. Same thing happens when you Open a file & forget to close it etc.

I hope this helps,

Newbie Coder




<bulld***@lycos.com> wrote in message
Show quoteHide quote
news:1165203332.534445.99140@f1g2000cwa.googlegroups.com...
> I've read numerous posts and have tried multiple approaches that I
> found, but just cannot get a file renamed.  I am using VB.Net 2002 ...
>
> Here is what I have tried:
>
> 1) Code common to all attempts:
>
> OldName = "c:\albums\061203\email\DSC07272.JPG"
> NewName = "c:\albums\061203\email\Lalala.JPG"
>
> sNewFileCheck = Dir(NewName)
>
> If sNewFileCheck = "" Then
>     ... followed by the below
>
> a) ReName(OldFile, NewFile)
> Error 53 : File not found
>                  I am assuming it cannot find the old file here ...
>
> b) System.IO.File.Move
> Error 57
> "The process cannot access the file
> "c:\albums\061203\email\Lalala.JPG" because it is being used by another
> process."
>
>                 - Very confusing, since Lalala.jpg did not exist prior
> to the Move call
>
> c) System.IO.File.Copy(OldFile, NewFile) works,
>     Kill(OldFile)   fails with
> Error 55
> "The process cannot access the file
> "c:\albums\061203\email\DSC07272.JPG" because it is being used by
> another process."
>      - Confusing also, since in debug I go and verify that the new file
> has been created.  Maybe adding a DoEvents before Kill?
>
>
> I wish VB was still simple and BASIC .....
>
> Any direction would be appreciated!
>
> - Jon
>
Author
14 Dec 2006 9:28 PM
bulldog8
Your code is basically what I have implemented.  Just to see if placing
it in a separate sub would help, I re-wrote to include your code as a
sub.

Still got Error 57 "The process cannot access the file
"c:\albums\061213\email\Xmas Kids1.JPG" because it is being used by
another process."

Where "c:\albums\061213\email\Xmas Kids1.JPG" is the NEW file name

Don't know what it would be in use by another process when the file
does not yet exist!

- Jon

Newbie Coder wrote:
Show quoteHide quote
> Imports System.IO
>
>     Private Sub RenameFile(ByVal sOldFile As String, ByVal sNewFile As
> String)
>         If File.Exists(sOldFile) = True Then
>             File.Move(sOldFile, sNewFile)
>         Else
>             MessageBox.Show("File to be renamed doesn't exist", "Rename
> Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
>         End If
>     End Sub
>
> Usage:
>
> RenameFile("C:\Test1.txt", "C:\Test2.txt")
> -------------------------------------------------------
>
> It sounds like your code failed trying to move the file therefor it kept the
> file locked open. This would explain why the file is being used by another
> process. Same thing happens when you Open a file & forget to close it etc.
>
> I hope this helps,
>
> Newbie Coder
>
>
>
>
> <bulld***@lycos.com> wrote in message
> news:1165203332.534445.99140@f1g2000cwa.googlegroups.com...
> > I've read numerous posts and have tried multiple approaches that I
> > found, but just cannot get a file renamed.  I am using VB.Net 2002 ...
> >
> > Here is what I have tried:
> >
> > 1) Code common to all attempts:
> >
> > OldName = "c:\albums\061203\email\DSC07272.JPG"
> > NewName = "c:\albums\061203\email\Lalala.JPG"
> >
> > sNewFileCheck = Dir(NewName)
> >
> > If sNewFileCheck = "" Then
> >     ... followed by the below
> >
> > a) ReName(OldFile, NewFile)
> > Error 53 : File not found
> >                  I am assuming it cannot find the old file here ...
> >
> > b) System.IO.File.Move
> > Error 57
> > "The process cannot access the file
> > "c:\albums\061203\email\Lalala.JPG" because it is being used by another
> > process."
> >
> >                 - Very confusing, since Lalala.jpg did not exist prior
> > to the Move call
> >
> > c) System.IO.File.Copy(OldFile, NewFile) works,
> >     Kill(OldFile)   fails with
> > Error 55
> > "The process cannot access the file
> > "c:\albums\061203\email\DSC07272.JPG" because it is being used by
> > another process."
> >      - Confusing also, since in debug I go and verify that the new file
> > has been created.  Maybe adding a DoEvents before Kill?
> >
> >
> > I wish VB was still simple and BASIC .....
> >
> > Any direction would be appreciated!
> >
> > - Jon
> >
Author
4 Jan 2007 1:16 PM
NickP
Have you tried using the new method for renaming files?

..NET 2.0.

My.Computer.FileSystem.RenameFile

Nick.

Show quoteHide quote
"Newbie Coder" <newbie_coder@pleasespamme.com> wrote in message
news:OcJS401FHHA.1276@TK2MSFTNGP04.phx.gbl...
> Imports System.IO
>
>    Private Sub RenameFile(ByVal sOldFile As String, ByVal sNewFile As
> String)
>        If File.Exists(sOldFile) = True Then
>            File.Move(sOldFile, sNewFile)
>        Else
>            MessageBox.Show("File to be renamed doesn't exist", "Rename
> Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
>        End If
>    End Sub
>
> Usage:
>
> RenameFile("C:\Test1.txt", "C:\Test2.txt")
> -------------------------------------------------------
>
> It sounds like your code failed trying to move the file therefor it kept
> the
> file locked open. This would explain why the file is being used by another
> process. Same thing happens when you Open a file & forget to close it etc.
>
> I hope this helps,
>
> Newbie Coder
>
>
>
>
> <bulld***@lycos.com> wrote in message
> news:1165203332.534445.99140@f1g2000cwa.googlegroups.com...
>> I've read numerous posts and have tried multiple approaches that I
>> found, but just cannot get a file renamed.  I am using VB.Net 2002 ...
>>
>> Here is what I have tried:
>>
>> 1) Code common to all attempts:
>>
>> OldName = "c:\albums\061203\email\DSC07272.JPG"
>> NewName = "c:\albums\061203\email\Lalala.JPG"
>>
>> sNewFileCheck = Dir(NewName)
>>
>> If sNewFileCheck = "" Then
>>     ... followed by the below
>>
>> a) ReName(OldFile, NewFile)
>> Error 53 : File not found
>>                  I am assuming it cannot find the old file here ...
>>
>> b) System.IO.File.Move
>> Error 57
>> "The process cannot access the file
>> "c:\albums\061203\email\Lalala.JPG" because it is being used by another
>> process."
>>
>>                 - Very confusing, since Lalala.jpg did not exist prior
>> to the Move call
>>
>> c) System.IO.File.Copy(OldFile, NewFile) works,
>>     Kill(OldFile)   fails with
>> Error 55
>> "The process cannot access the file
>> "c:\albums\061203\email\DSC07272.JPG" because it is being used by
>> another process."
>>      - Confusing also, since in debug I go and verify that the new file
>> has been created.  Maybe adding a DoEvents before Kill?
>>
>>
>> I wish VB was still simple and BASIC .....
>>
>> Any direction would be appreciated!
>>
>> - Jon
>>
>
>
Author
4 Dec 2006 9:28 AM
Master Programmer
VB was simple and useful. VB.NET is not simple or useful - it is slow
and tedious.

Steve Ray Irwin

bulld***@lycos.com wrote:
Show quoteHide quote
> I've read numerous posts and have tried multiple approaches that I
> found, but just cannot get a file renamed.  I am using VB.Net 2002 ...
>
> Here is what I have tried:
>
> 1) Code common to all attempts:
>
> OldName = "c:\albums\061203\email\DSC07272.JPG"
> NewName = "c:\albums\061203\email\Lalala.JPG"
>
> sNewFileCheck = Dir(NewName)
>
> If sNewFileCheck = "" Then
>     ... followed by the below
>
> a) ReName(OldFile, NewFile)
>     Error 53 : File not found
>                  I am assuming it cannot find the old file here ...
>
> b) System.IO.File.Move
>     Error 57
>     "The process cannot access the file
> "c:\albums\061203\email\Lalala.JPG" because it is being used by another
> process."
>
>                 - Very confusing, since Lalala.jpg did not exist prior
> to the Move call
>
> c) System.IO.File.Copy(OldFile, NewFile) works,
>     Kill(OldFile)   fails with
>     Error 55
>     "The process cannot access the file
> "c:\albums\061203\email\DSC07272.JPG" because it is being used by
> another process."
>      - Confusing also, since in debug I go and verify that the new file
> has been created.  Maybe adding a DoEvents before Kill?
>
>
> I wish VB was still simple and BASIC .....
>
> Any direction would be appreciated!
>
> - Jon
Author
4 Dec 2006 3:27 PM
NickP
?

From "Master Programmer"?

Yeah okay mate...

Show quoteHide quote
"Master Programmer" <master_program***@outgun.com> wrote in message
news:1165224488.745820.36240@16g2000cwy.googlegroups.com...
> VB was simple and useful. VB.NET is not simple or useful - it is slow
> and tedious.
>
> Steve Ray Irwin
>
> bulld***@lycos.com wrote:
>> I've read numerous posts and have tried multiple approaches that I
>> found, but just cannot get a file renamed.  I am using VB.Net 2002 ...
>>
>> Here is what I have tried:
>>
>> 1) Code common to all attempts:
>>
>> OldName = "c:\albums\061203\email\DSC07272.JPG"
>> NewName = "c:\albums\061203\email\Lalala.JPG"
>>
>> sNewFileCheck = Dir(NewName)
>>
>> If sNewFileCheck = "" Then
>>     ... followed by the below
>>
>> a) ReName(OldFile, NewFile)
>> Error 53 : File not found
>>                  I am assuming it cannot find the old file here ...
>>
>> b) System.IO.File.Move
>> Error 57
>> "The process cannot access the file
>> "c:\albums\061203\email\Lalala.JPG" because it is being used by another
>> process."
>>
>>                 - Very confusing, since Lalala.jpg did not exist prior
>> to the Move call
>>
>> c) System.IO.File.Copy(OldFile, NewFile) works,
>>     Kill(OldFile)   fails with
>> Error 55
>> "The process cannot access the file
>> "c:\albums\061203\email\DSC07272.JPG" because it is being used by
>> another process."
>>      - Confusing also, since in debug I go and verify that the new file
>> has been created.  Maybe adding a DoEvents before Kill?
>>
>>
>> I wish VB was still simple and BASIC .....
>>
>> Any direction would be appreciated!
>>
>> - Jon
>