vb.net wildcard file search exception
up vote
1
down vote
favorite
im totally new to vb.net
I figured how to find files using wildcard and it works fine but i need error meassage if file not found.
here's my code.
any help highly appreciated !
For Each hist In Directory.GetFiles("C:temp", "*.*", SearchOption.TopDirectoryOnly)
If File.Exists(hist) Then
File.Copy(hist, Path.Combine("C:temp1", Path.GetFileName(hist)), True)
MessageBox.Show("file exist and copied") <-- this message shows up and files are copied
Else
MessageBox.Show("No files. Folder is empty !") <--this message never shows up when folder is empty . no files at all
End If
Next
vb.net file wildcard messagebox
New contributor
add a comment |
up vote
1
down vote
favorite
im totally new to vb.net
I figured how to find files using wildcard and it works fine but i need error meassage if file not found.
here's my code.
any help highly appreciated !
For Each hist In Directory.GetFiles("C:temp", "*.*", SearchOption.TopDirectoryOnly)
If File.Exists(hist) Then
File.Copy(hist, Path.Combine("C:temp1", Path.GetFileName(hist)), True)
MessageBox.Show("file exist and copied") <-- this message shows up and files are copied
Else
MessageBox.Show("No files. Folder is empty !") <--this message never shows up when folder is empty . no files at all
End If
Next
vb.net file wildcard messagebox
New contributor
Why would it ever show up? Why are you expecting a file that you just found to not be found? Are you actually wanting to show that message if there are no files at all? If so, assign the result ofGetFiles
to a variable and then test theLength
of the array or callAny
. That will tell you if there are files or not and, if not, you can display your message. If there are files, then you loop through them.
– jmcilhinney
14 hours ago
Yes. I.m expecting 2nd message only if there are no files atl. empty folder.
– czechu82
6 hours ago
@czechu82 If there are no files in the target folder, the foreach loop won't execute any iterations.
– Ryan Pierce Williams
5 hours ago
thanks for help
– czechu82
3 hours ago
add a comment |
up vote
1
down vote
favorite
up vote
1
down vote
favorite
im totally new to vb.net
I figured how to find files using wildcard and it works fine but i need error meassage if file not found.
here's my code.
any help highly appreciated !
For Each hist In Directory.GetFiles("C:temp", "*.*", SearchOption.TopDirectoryOnly)
If File.Exists(hist) Then
File.Copy(hist, Path.Combine("C:temp1", Path.GetFileName(hist)), True)
MessageBox.Show("file exist and copied") <-- this message shows up and files are copied
Else
MessageBox.Show("No files. Folder is empty !") <--this message never shows up when folder is empty . no files at all
End If
Next
vb.net file wildcard messagebox
New contributor
im totally new to vb.net
I figured how to find files using wildcard and it works fine but i need error meassage if file not found.
here's my code.
any help highly appreciated !
For Each hist In Directory.GetFiles("C:temp", "*.*", SearchOption.TopDirectoryOnly)
If File.Exists(hist) Then
File.Copy(hist, Path.Combine("C:temp1", Path.GetFileName(hist)), True)
MessageBox.Show("file exist and copied") <-- this message shows up and files are copied
Else
MessageBox.Show("No files. Folder is empty !") <--this message never shows up when folder is empty . no files at all
End If
Next
vb.net file wildcard messagebox
vb.net file wildcard messagebox
New contributor
New contributor
edited 6 hours ago
New contributor
asked 14 hours ago
czechu82
62
62
New contributor
New contributor
Why would it ever show up? Why are you expecting a file that you just found to not be found? Are you actually wanting to show that message if there are no files at all? If so, assign the result ofGetFiles
to a variable and then test theLength
of the array or callAny
. That will tell you if there are files or not and, if not, you can display your message. If there are files, then you loop through them.
– jmcilhinney
14 hours ago
Yes. I.m expecting 2nd message only if there are no files atl. empty folder.
– czechu82
6 hours ago
@czechu82 If there are no files in the target folder, the foreach loop won't execute any iterations.
– Ryan Pierce Williams
5 hours ago
thanks for help
– czechu82
3 hours ago
add a comment |
Why would it ever show up? Why are you expecting a file that you just found to not be found? Are you actually wanting to show that message if there are no files at all? If so, assign the result ofGetFiles
to a variable and then test theLength
of the array or callAny
. That will tell you if there are files or not and, if not, you can display your message. If there are files, then you loop through them.
– jmcilhinney
14 hours ago
Yes. I.m expecting 2nd message only if there are no files atl. empty folder.
– czechu82
6 hours ago
@czechu82 If there are no files in the target folder, the foreach loop won't execute any iterations.
– Ryan Pierce Williams
5 hours ago
thanks for help
– czechu82
3 hours ago
Why would it ever show up? Why are you expecting a file that you just found to not be found? Are you actually wanting to show that message if there are no files at all? If so, assign the result of
GetFiles
to a variable and then test the Length
of the array or call Any
. That will tell you if there are files or not and, if not, you can display your message. If there are files, then you loop through them.– jmcilhinney
14 hours ago
Why would it ever show up? Why are you expecting a file that you just found to not be found? Are you actually wanting to show that message if there are no files at all? If so, assign the result of
GetFiles
to a variable and then test the Length
of the array or call Any
. That will tell you if there are files or not and, if not, you can display your message. If there are files, then you loop through them.– jmcilhinney
14 hours ago
Yes. I.m expecting 2nd message only if there are no files atl. empty folder.
– czechu82
6 hours ago
Yes. I.m expecting 2nd message only if there are no files atl. empty folder.
– czechu82
6 hours ago
@czechu82 If there are no files in the target folder, the foreach loop won't execute any iterations.
– Ryan Pierce Williams
5 hours ago
@czechu82 If there are no files in the target folder, the foreach loop won't execute any iterations.
– Ryan Pierce Williams
5 hours ago
thanks for help
– czechu82
3 hours ago
thanks for help
– czechu82
3 hours ago
add a comment |
2 Answers
2
active
oldest
votes
up vote
2
down vote
It is unlikely you would see that second message. You are grabbing the list of files from the OS directly - so, at least at the time that you retrieve the file name that file exists. If you wanted to simulate a case where the file doesn't exist, place a break point on the IF File.Exists(hist) Then line. While the program is paused there, go find and delete whatever the current file is. Then continue the program.
add a comment |
up vote
0
down vote
i got it working.
here's what i added before foreach :
Dim myDir As DirectoryInfo = New DirectoryInfo("c:temp")
If (myDir.EnumerateFiles().Any()) Then
foreach ....
else
MessageBox.Show("no files in directory ") <-- my message
thanks for advice!!
New contributor
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
It is unlikely you would see that second message. You are grabbing the list of files from the OS directly - so, at least at the time that you retrieve the file name that file exists. If you wanted to simulate a case where the file doesn't exist, place a break point on the IF File.Exists(hist) Then line. While the program is paused there, go find and delete whatever the current file is. Then continue the program.
add a comment |
up vote
2
down vote
It is unlikely you would see that second message. You are grabbing the list of files from the OS directly - so, at least at the time that you retrieve the file name that file exists. If you wanted to simulate a case where the file doesn't exist, place a break point on the IF File.Exists(hist) Then line. While the program is paused there, go find and delete whatever the current file is. Then continue the program.
add a comment |
up vote
2
down vote
up vote
2
down vote
It is unlikely you would see that second message. You are grabbing the list of files from the OS directly - so, at least at the time that you retrieve the file name that file exists. If you wanted to simulate a case where the file doesn't exist, place a break point on the IF File.Exists(hist) Then line. While the program is paused there, go find and delete whatever the current file is. Then continue the program.
It is unlikely you would see that second message. You are grabbing the list of files from the OS directly - so, at least at the time that you retrieve the file name that file exists. If you wanted to simulate a case where the file doesn't exist, place a break point on the IF File.Exists(hist) Then line. While the program is paused there, go find and delete whatever the current file is. Then continue the program.
answered 14 hours ago
Ryan Pierce Williams
31317
31317
add a comment |
add a comment |
up vote
0
down vote
i got it working.
here's what i added before foreach :
Dim myDir As DirectoryInfo = New DirectoryInfo("c:temp")
If (myDir.EnumerateFiles().Any()) Then
foreach ....
else
MessageBox.Show("no files in directory ") <-- my message
thanks for advice!!
New contributor
add a comment |
up vote
0
down vote
i got it working.
here's what i added before foreach :
Dim myDir As DirectoryInfo = New DirectoryInfo("c:temp")
If (myDir.EnumerateFiles().Any()) Then
foreach ....
else
MessageBox.Show("no files in directory ") <-- my message
thanks for advice!!
New contributor
add a comment |
up vote
0
down vote
up vote
0
down vote
i got it working.
here's what i added before foreach :
Dim myDir As DirectoryInfo = New DirectoryInfo("c:temp")
If (myDir.EnumerateFiles().Any()) Then
foreach ....
else
MessageBox.Show("no files in directory ") <-- my message
thanks for advice!!
New contributor
i got it working.
here's what i added before foreach :
Dim myDir As DirectoryInfo = New DirectoryInfo("c:temp")
If (myDir.EnumerateFiles().Any()) Then
foreach ....
else
MessageBox.Show("no files in directory ") <-- my message
thanks for advice!!
New contributor
New contributor
answered 3 hours ago
czechu82
62
62
New contributor
New contributor
add a comment |
add a comment |
czechu82 is a new contributor. Be nice, and check out our Code of Conduct.
czechu82 is a new contributor. Be nice, and check out our Code of Conduct.
czechu82 is a new contributor. Be nice, and check out our Code of Conduct.
czechu82 is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53224034%2fvb-net-wildcard-file-search-exception%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Why would it ever show up? Why are you expecting a file that you just found to not be found? Are you actually wanting to show that message if there are no files at all? If so, assign the result of
GetFiles
to a variable and then test theLength
of the array or callAny
. That will tell you if there are files or not and, if not, you can display your message. If there are files, then you loop through them.– jmcilhinney
14 hours ago
Yes. I.m expecting 2nd message only if there are no files atl. empty folder.
– czechu82
6 hours ago
@czechu82 If there are no files in the target folder, the foreach loop won't execute any iterations.
– Ryan Pierce Williams
5 hours ago
thanks for help
– czechu82
3 hours ago