473,394 Members | 1,797 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,394 software developers and data experts.

Can not delete a file that is read-only after file.copy

I have a function to copare two files. It will first copy the original file
form a different server to a local temp path and then compare that version to
a version that has been restored form tape. Once the compare is complete the
file that was copied to a temp location needs to be deleted. I am using the
method file.copy(sourcePath, tempPath, true) to copy the file and then
file.delete(tempPath) to delete the file. On some of the files that I am
comparing I am getting

Access to the path "tempPath" is denied.

when I try and delete the file. The only thing that I can find different is
that any file I can not delete is READ-ONLY. The app is running under an
account that is local admin and has full rights to all the directories. Here
is my compare function:
Function FileByteCompareWithCopy(ByVal file1 As String, ByVal file2 As
String) As Integer

Dim file1byte As Integer
Dim file2byte As Integer
Dim fs1 As FileStream
Dim fs2 As FileStream
Dim filePath() As String
Dim copiedFileName As String
Dim errorDescription As String
Dim errorNumber As Integer
Dim moveFileLog As StreamWriter = New StreamWriter(g_sReportDataPath
& "CopyReport_" & g_sTestTime & ".txt", True)

On Error Resume Next
Err.Clear()

'* Get the file name and then append the temp loaction to copy the
file to.
filePath = Split(file1, "\")
copiedFileName = g_tempPath & filePath(UBound(filePath))

'* Copy file to temp locatoin
File.Copy(file1, copiedFileName, True)

If Err.Number > 0 Then
moveFileLog.WriteLine("Copy: " & Err.Description & " " &
copiedFileName)
moveFileLog.Close()
Return 2
End If

'* Open the original file
fs1 = New FileStream(copiedFileName, FileMode.Open, FileAccess.Read,
FileShare.Read)

'* Open the restored file
fs2 = New FileStream(file2, FileMode.Open, FileAccess.Read,
FileShare.Read)

'* Read and compare byte for byte file1 and file2
Do
file1byte = fs1.ReadByte()
file2byte = fs2.ReadByte
Loop While ((file1byte = file2byte) And (file1byte <> -1))

'* Close Files
fs1.Close()
fs2.Close()

Err.Clear()
'* Delete File from temp location
File.Delete(copiedFileName)

If Err.Number > 0 Then
moveFileLog.WriteLine("Delete: " & Err.Description & " " &
copiedFileName)
End If

moveFileLog.Close()

'* Return the result of the comparison
Return ((file1byte - file2byte) = 0)

End Function
Jul 21 '05 #1
0 2068

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

Similar topics

1
by: Douglas Peterson | last post by:
class Allocator { public: virtual void * Alloc(size_t) = 0; virtual void * Free(void*) = 0; }; class Object { public:
3
by: Ryan Liu | last post by:
Hi there, I got a NullReferenceException when delete last row in a datagrid. I had hard time to solve since it does not occur in my own code. I put a datagrid in my inherited user control,...
4
by: Elliot M. Rodriguez | last post by:
I have a Delete button in my datagrid. I'm attempting to add some code confirming whether the user wishes to really delete the item or not. The confirm pops up, but I cannot suppress the...
19
by: Xavier Décoret | last post by:
Hi, I long thought one could not delete a const pointer but the following code compiles under g++ and visual net: class Dummy { public: Dummy() {} ~Dummy() {}
13
by: forbes | last post by:
Hi, I have a user that used the Query Wizard to create a query in Access. Now she claims that her master table is missing all the data that was excluded from the query. Can you create anything...
5
by: mkaushik | last post by:
Hi everyone, Im just starting out with C++, and am curious to know how "delete <pointer>", knows about the number of memory locations to free. I read somewhere that delete frees up space...
12
by: yufufi | last post by:
Hello, How does delete know how much memory to deallocate from the given pointer? AFAIK this informations is put there by new. new puts the size of the allocated memory before the just before...
7
by: czechboy | last post by:
Hi, I would like to send DELETE request to google calendar but nothing of this works: xmlhttp.open("POST",del,false); xmlhttp.setRequestHeader("X-HTTP-Method-Override", "DELETE");...
3
by: dizzy | last post by:
Hi I wonder if this code is standard conformant and should work on all conformant implementations (for some type T): 1: void* mem = ::operator new(sizeof(T)); 2: T* p = new(mem) T(args...);...
4
by: mail.dsp | last post by:
Suppose in a class we overload four operators: operator new operator delete operator new operator delete class Test{ public: void * operator new (size_t t){ cout<<"\nCalling... new";
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
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...

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.