473,387 Members | 1,698 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Aaargh!! Renaming file issues

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

Dec 4 '06 #1
5 4697
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


<bu******@lycos.comwrote in message
news:11*********************@f1g2000cwa.googlegrou ps.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

Dec 4 '06 #2
VB was simple and useful. VB.NET is not simple or useful - it is slow
and tedious.

Steve Ray Irwin

bu******@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
Dec 4 '06 #3
?

From "Master Programmer"?

Yeah okay mate...

"Master Programmer" <ma***************@outgun.comwrote in message
news:11*********************@16g2000cwy.googlegrou ps.com...
VB was simple and useful. VB.NET is not simple or useful - it is slow
and tedious.

Steve Ray Irwin

bu******@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

Dec 4 '06 #4
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:
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


<bu******@lycos.comwrote in message
news:11*********************@f1g2000cwa.googlegrou ps.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
Dec 14 '06 #5
Have you tried using the new method for renaming files?

..NET 2.0.

My.Computer.FileSystem.RenameFile

Nick.

"Newbie Coder" <ne**********@pleasespamme.comwrote in message
news:Oc**************@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


<bu******@lycos.comwrote in message
news:11*********************@f1g2000cwa.googlegrou ps.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


Jan 4 '07 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Sergey Balan | last post by:
Here's a problem User can download *.eps files. For example - 'blah.eps' Cutted from ascx control: <a href="../public/download/blah.eps" target="_blank">blah file (476 eps)</a> When user...
4
by: bdan44 | last post by:
i am a total n00b at perl. i just started learning yesterday. I wanted to make a script to rename extentions. this is what i've come up with. i can't figure out why it doesn't work. any help would be...
1
by: rush81 | last post by:
i'm trying to create an ssis package for renaming and moving the file. It gives error at the file system task: Error: An error occurred with the following error message: "Could not find file...
2
by: zacks | last post by:
A couple of the engineers I work with are seeing a strange problem with an application I developed in .NET 2.0. I am suspecting this is being caused by the environment since so far it only happens...
2
by: steve | last post by:
I am reading in a bitmap file using the microsoft bmp classes and most all of the files are as follows Width :640: Height :480: Bits :8: Upside Down :1: Core :0: Palette Size :256:...
2
by: djcamo | last post by:
Hi, I'm hoping some one can help with some coding issues I'm having. Below is some code I use to rename a file if it already exists in a folder. As you can see I have 5 nested if loops which means...
4
AnuSumesh
by: AnuSumesh | last post by:
Hi All, Our company is providing remote access to employees to all the shared files/folders that exists on all the servers in the same network. For this purpose dll file is used. e.g I can access...
1
by: samelamin | last post by:
Hello, I was wondering if anyone could help me in this really tricky issue i have been working on. I am working with a programs APIs that receives parameters and then excutes commands and gives back...
0
by: paulbones | last post by:
Hi I have this script that works for me but I want to add a date and or time of upload to the name of the file being uploaded, using this form, but want to keep the original file name as well . All...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.