473,659 Members | 2,667 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

copy and then Delete a file.

I getting the following message when using Filecopy command
An unhandled exception of type 'System.NullRef erenceException ' occurred in
Unknown Module.

Additional information: Object reference not set to an instance of an
object.

If I break then I get "There is no source code avaliable for the current
location.
If I Continue I get the following

An unhandled exception of type 'System.Unautho rizedAccessExce ption' occurred
in microsoft.visua lbasic.dll

Additional information: Access to the path "c:\test\Adshel After850-51.jpg"
is denied.

I have not the file loaded in any programs or looking on that file location.
I have full admin rights localy on my computer. The task is to watch for
files put in Directoy c:\A and then move it to c:\B at the moment.

Have someone any clue to what is wrong her ?

Petter L.
Jul 21 '05 #1
4 1640
Petter,

A nullreference is almost forever a non instanced object.
However the rest probably nobody can see without a little piece of code.

I hope this starts helps?

Cor
Jul 21 '05 #2
Here is a pice of the code
Private m_WatchDirector y As String

Private WithEvents m_FileSystemWat cher As FileSystemWatch er

Dim log As New Log

Private Sub Form1_Load(ByVa l sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load

lstFiles.Items. Add(Now.ToStrin g() & " Starting")

readReg()

log.lstFiles.It ems.Add(Now.ToS tring() & " Init " & LookPath)

log.lstFiles.It ems.Add(Now.ToS tring() & " Init " & ToPath)

' Get the path to the directory we will watch.

m_WatchDirector y = LookPath 'Application.St artupPath

' m_WatchDirector y = m_WatchDirector y.Substring(0,
m_WatchDirector y.LastIndexOf(" \"))

'm_WatchDirecto ry &= LookPath '"\Files"

' Make the FileSystemWatch er.

m_FileSystemWat cher = New FileSystemWatch er(m_WatchDirec tory, "*.*") '
"*.txt")

m_FileSystemWat cher.NotifyFilt er = 0

m_FileSystemWat cher.NotifyFilt er = m_FileSystemWat cher.NotifyFilt er Or
NotifyFilters.F ileName

m_FileSystemWat cher.EnableRais ingEvents = True

m_FileSystemWat cher.IncludeSub directories = alldirs

' Process any files that already exist.

MsgBox(m_WatchD irectory)

ProcessExisting Files(m_WatchDi rectory)
End Sub

Private Sub ProcessExisting Files(ByVal directory_name As String)

Dim dir_info As New DirectoryInfo(d irectory_name)

Dim file_infos As FileInfo() = dir_info.GetFil es()

For Each fi As FileInfo In file_infos

ProcessFile(fi. FullName, fi.Name)

Next fi

End Sub

Private Sub ProcessFile(ByV al file_name As String, ByVal shName As String)

log.lstFiles.It ems.Add(Now.ToS tring() & " Processed " & file_name)

If shName = "\Thumbs.db " Then ' = LCase(file_name ) Then

Exit Sub

End If

MsgBox(file_nam e & " " & ToPath & "\" & shName)

FileCopy(file_n ame, ToPath & "\" & shName)

Kill(file_name)

End Sub

I also have the following in a module file

Public LookPath, ToPath As String

Public AllDirs As Boolean

Petter L.
"Cor Ligthert" <no************ @planet.nl> wrote in message
news:uR******** ******@TK2MSFTN GP15.phx.gbl...
Petter,

A nullreference is almost forever a non instanced object.
However the rest probably nobody can see without a little piece of code.

I hope this starts helps?

Cor

Jul 21 '05 #3
Peter,

When you want to give us some code to help you, than please make it
readable, all rows which are deleted with a ', makes it for others even more
unreadable what your code is now.

And than past it fist in a notebook, and than copy it back before you paste
it in your message.

When I look at your code am I directly thinking why is Peter not using the
File class to do things as deleting files.

http://msdn.microsoft.com/library/de...eletetopic.asp

I hope this helps somehow?

Cor
"Petter L" <petter at ho**@hotmail.co m>

Here is a pice of the code
Private m_WatchDirector y As String

Private WithEvents m_FileSystemWat cher As FileSystemWatch er

Dim log As New Log

Private Sub Form1_Load(ByVa l sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load

lstFiles.Items. Add(Now.ToStrin g() & " Starting")

readReg()

log.lstFiles.It ems.Add(Now.ToS tring() & " Init " & LookPath)

log.lstFiles.It ems.Add(Now.ToS tring() & " Init " & ToPath)

' Get the path to the directory we will watch.

m_WatchDirector y = LookPath 'Application.St artupPath

' m_WatchDirector y = m_WatchDirector y.Substring(0,
m_WatchDirector y.LastIndexOf(" \"))

'm_WatchDirecto ry &= LookPath '"\Files"

' Make the FileSystemWatch er.

m_FileSystemWat cher = New FileSystemWatch er(m_WatchDirec tory, "*.*") '
"*.txt")

m_FileSystemWat cher.NotifyFilt er = 0

m_FileSystemWat cher.NotifyFilt er = m_FileSystemWat cher.NotifyFilt er Or
NotifyFilters.F ileName

m_FileSystemWat cher.EnableRais ingEvents = True

m_FileSystemWat cher.IncludeSub directories = alldirs

' Process any files that already exist.

MsgBox(m_WatchD irectory)

ProcessExisting Files(m_WatchDi rectory)
End Sub

Private Sub ProcessExisting Files(ByVal directory_name As String)

Dim dir_info As New DirectoryInfo(d irectory_name)

Dim file_infos As FileInfo() = dir_info.GetFil es()

For Each fi As FileInfo In file_infos

ProcessFile(fi. FullName, fi.Name)

Next fi

End Sub

Private Sub ProcessFile(ByV al file_name As String, ByVal shName As String)

log.lstFiles.It ems.Add(Now.ToS tring() & " Processed " & file_name)

If shName = "\Thumbs.db " Then ' = LCase(file_name ) Then

Exit Sub

End If

MsgBox(file_nam e & " " & ToPath & "\" & shName)

FileCopy(file_n ame, ToPath & "\" & shName)

Kill(file_name)

End Sub

I also have the following in a module file

Public LookPath, ToPath As String

Public AllDirs As Boolean

Petter L.
"Cor Ligthert" <no************ @planet.nl> wrote in message
news:uR******** ******@TK2MSFTN GP15.phx.gbl...
Petter,

A nullreference is almost forever a non instanced object.
However the rest probably nobody can see without a little piece of code.

I hope this starts helps?

Cor


Jul 21 '05 #4
Is it possible that the process that is writing the file is not
finished when the FileSystemWatch er attempts to move the file?

You might try opening the file in exclusive mode first and if that
succeeds, then try moving the file. If that fails, wait a few seconds
and try again.

Just a thought

Jul 21 '05 #5

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

Similar topics

0
2091
by: SeanR | last post by:
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...
3
2926
by: News | last post by:
Is it possible to delete a file by copying it to the "bit bucket" or "null device"? Back in my youth when I live in VMS-land you could delete a file by copying it to NL: ========== I have written a windows service as part of an interface between two different systems. The first system will write output into a file in a
0
334
by: SeanR | last post by:
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...
5
1380
by: Hans Munich | last post by:
Szenario: User selects a XML File ("products.xml") to import newest Data. Data should replace Data in an existing Acess File which is connected via Dataadapter (daadaptFLR). Bevore the Existing Data are deleted with RunSQL("DELETE * From Tbl_Fl_Rundleitung"). Function the Works: If I copy the File from the directory of the Application.exe then it works fine.
25
2875
by: Andy_Khosravi | last post by:
I just recently changed my database that I'm running from a monolithic DB to a split FE/BE. The front end resides on the client machine and the BE resides on a network drive. I'm experimenting with a utility developed by Tony Toews to handle the distribution and subsequent updates of the software. I'm having some trouble with the overall upgrade process I've implemented, and I'm hoping one of you may have an idea how to go about fixing...
0
8428
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8339
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8851
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8535
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6181
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5650
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4176
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
1982
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1739
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.