|
Hello,
I want to search a set of directories that are organized by "LastName FirstName". However, the number of spaces between each name might vary (most only have 1 space, but some have 2 or 3 b/c of a typo). The only search pattern I know of to accommodate this is "LastName*FirstName", but I'd rather use some regex like "LastName[ ]+FirstName", that only allows spaces between the names. Is this possible, or would I just have to get all directories and manually evaluate the regex on each one?
Thanks,
Dybs
|
|
|
|
|
You have to get the list of files and RegEx each one yourself to find the matches. The search options in the GetFiles methods, or whatever else you use, do not support RegEx expressions and there is no search option that will only match "any number of spaces".
|
|
|
|
|
Dave,
I thought as much, but wanted to confirm. Thanks.
Dybs
|
|
|
|
|
You'd wish the 'search pattern' worked like a wildcard, but it doesn't. Well, maybe just barely in that it's limited to the wildcards '*' and '?'. I got what I needed using LINQ and regular expressions:
DirectoryInfo[] jobs =
_dirJobsFolder.GetDirectories();
if (jobs.Length == 0) return null;
Regex r = new Regex("\d\d\d\d"); // Four digits
var joblist = from job in jobs
where r.IsMatch(job.ToString())
orderby job.ToString() ascending
select job.ToString();
_Jobs = (string[])joblist.ToArray();
|
|
|
|
|
I want to built a setup including database of sqlserver2000 with file of *.sql , I install the program whiling auto install my database and table or trigger ect,thank you for help me!
|
|
|
|
|
I have a third party api that seems only to work in a winform, not within a windows service or console program. From the look of the api it seems to be message based.
Is it possible to somehow make a c# winform invisible. Or, how can I add a message queue to my c# windows service to see if that is what is needed?
|
|
|
|
|
How about asking the people who wrote the library??
|
|
|
|
|
jspoonermso wrote: Is it possible to somehow make a c# winform invisible.
Yep, i'd set the Visible property to false
private void FormName_Load(object sender, EventArgs e)
{
this.Visible = false;
}
|
|
|
|
|
Just dropping a form in a service, visible or no, doesn't give the serivce a message pump.
|
|
|
|
|
Hi Dave,
I don't mean to butt in here, but.... The OP is not exactly clear, however the way I understood it was he's got a 3rd party thing that works in a WinForm. He'd like to use it in a service but it doesn't work for reasons unknown to us. He'd settle for using it in a form but would like to hide it and "pretend" it's a service. Of course he can't start, stop, or communicate with it like it is a service but beggars can't be choosers.
BDF
People don't mind being mean; but they never want to be ridiculous.
-- Moliere
|
|
|
|
|
Yes thats correct, my quyestion wasn't clear. My third party component seems only to work in forms and its just my guess that it wants a message pump, because there is an api function with the word 'advise' in it.
I did try setting my visibility to 'False'. If it were c++ there was something like ShowWindow(SW_HIDE) that would do the trick.
|
|
|
|
|
Again, you're guessing. Your best source of information is the people who wrote the library.
|
|
|
|
|
Sorry for my inadequate guessing but i don't have that recourse.
So I have found a way to make my program work in my own inferior wild guessing method.
I have a program that has a message pump is invisible and seems to do the job. My original question was about making the form invisible since setting the visible property didnt work. all figured out now.
|
|
|
|
|
Yeah I know, I didn't bother replying to that portion of the question simply because you're suggestion of contacting the vendor / developer is the best bet, I was just trying to tell him the form has a visibility property which was the first half of his question.
|
|
|
|
|
You would think. I tried that and my form still popped up.
|
|
|
|
|
Don't you hate when that happens?
Here are some other things to try. You can do these in the Properties window of Visual Studio:
<br />
this.ShowInTaskbar = false;<br />
this.WindowState = System.Windows.Forms.FormWindowState.Minimized;<br />
And/or this in load event handler:
this.Hide();
Hope that helps.
BDF
People don't mind being mean; but they never want to be ridiculous.
-- Moliere
|
|
|
|
|
I found a means to do it on the web. The 'Visible' property stubbornly did not work for me. But I was able to use the win32 ShowWindow Function. Code below.
And yes, you guys are correct its better to have a windows service, and it would be better if my third party dll would work without a message pump but its a legacy application. My guess is it uses netdde which is windows message based.
So the fix was to :
using System.Diagnostics;
using System.Runtime.InteropServices;
Then get access to the Win32 ShowWindow API call:
private const int SW_HIDE = 0;
[DllImport("User32")]
private static extern int ShowWindow(int hwnd, int nCmdShow);
Then when the form loads call a function that goes out, finds the app and hides it.
foreach (Process pr in processRunning)
{
try
{
if ((pr.MainWindowTitle == "mywindowname")||pr.ProcessName.Contains("mywindow.exe"))
{
hWnd = pr.MainWindowHandle.ToInt32();
ShowWindow(hWnd, SW_HIDE);
}
}
catch (Exception)
{
}
}
|
|
|
|
|
Your idea brought my mind another idea about my another project . Thank you.
By the way you can use this code to hide your Form.
private void Form1_Load(object sender, EventArgs e)
{
this.Opacity = 0.0f;
this.WindowState = FormWindowState.Minimized;
this.ShowInTaskbar = false;
}
|
|
|
|
|
Hello friends,
I have written this small piece of code to detect autorun.inf files, particularly in the C: and the D: drive:-
<br />
using System;<br />
using System.IO;<br />
class search<br />
{<br />
public static void Main()<br />
{<br />
Console.WriteLine("Autorun checker");<br />
if (File.Exists("C:/autorun.inf") || File.Exists("D:/autorun.inf"))<br />
{<br />
Console.WriteLine("Autorun Detected. Press Enter to delete it.");<br />
Console.ReadLine();<br />
File.Delete("C:/autorun.inf");<br />
File.Delete("D:/autorun.inf");<br />
Console.WriteLine("Autorun Deleted successfully.");<br />
Console.ReadLine();<br />
}<br />
else<br />
{<br />
Console.WriteLine("No Autorun Detected. Press Enter to exit.");<br />
Console.ReadLine();<br />
}<br />
}<br />
}<br />
Now, if no autorun files are detected in C:/ or D:/ drive, the program exits displaying "No Autorun Detected. Press Enter to Exit." But if detected, it successfully deletes that autorun file but throws a runtime exception. Suppose, it has detected an autorun.inf file in the C:/ drive, it will delete that file but throw some kind of exception like this:
File.Delete("D:/autorun.inf");
<br />
IOException was unhandled. The device is not ready
Can anyone help me out! I am new to .NET programming and dont posses that much knowledge about Exception handling.
Hope to hear from you guys soon,
Rajdeep.NET
|
|
|
|
|
This may be a silly question, but is your D: drive by any chance a CD or DVD drive? If so, then deleting files may not be too easy...
Oh, and PLEASE, use the code block button - it makes things easier to read.
If what you are trying to do is handle the error cleanly:
using System;
using System.IO;
class search
{
public static void Main()
{
Console.WriteLine("Autorun checker");
if (File.Exists(@"C:\autorun.inf") || File.Exists(@"D:\autorun.inf"))
{
Console.WriteLine("Autorun Detected. Press Enter to delete it.");
Console.ReadLine();
try
{
File.Delete(@"C:\autorun.inf");
}
catch (IOException ex)
{
Console.WriteLine("Unable to delete C:\\autorun.inf:\n{0}", ex);
}
try
{
File.Delete(@"D:\autorun.inf");
}
catch (IOException ex)
{
Console.WriteLine("Unable to delete D:\\autorun.inf:\n{0}", ex);
}
Console.WriteLine("Autorun Deleted successfully.");
Console.ReadLine();
}
else
{
Console.WriteLine("No Autorun Detected. Press Enter to exit.");
Console.ReadLine();
}
}
}
No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced.
This message is made of fully recyclable Zeros and Ones
|
|
|
|
|
Hey Griff,
Thanks for correcting the code man. And yes, I remember to post the codes in the code block in my further posts.
Thanks once again,
Rajdeep.NET
|
|
|
|
|
Answer[^]
My failometer is detecting vast quantities of FAIL!
"Its SQL - hardly programming..." (Caslen)
|
|
|
|
|
Don't you think its about time you begged, borrowed or stole a C# Primer Book and worked through it?
You really should be fed up with posting such elementary mistakes, I know I am.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
Hear hear.
|
|
|
|
|
Hello,
I am writing a small console application which will accept user age and name under the Public void Accept_Details() function. Now I want that, on the basis of the input provided by the user in the public void Display_Details() function, he be shown the desired output. Like this:
Console.WriteLine("Enter your choice. Type 'age' to view user age or 'name' to view user name);
Now, if the user enters 'age', he will be shown this:
Console.WriteLine("User Age is: {0}", age);
Similar will be the case, if the user enters 'name'. How to do that?
Please help me out,
sorry for my poor english,
Rajdeep.NET
|
|
|
|