|
I would agree...
...except the phrase is ONLY used in sarcasm and has no other meaning.
|
|
|
|
|
if you say so , but if you weren't going to be helpful , then u could of just carried on ....
|
|
|
|
|
You're using C#, or VB ? I'm confused. Either way, the best way to learn, is not to look at other source code, not at first. you would do better to work through the examples in a C# book, if you're starting out. From there, you'll understand enough to read up on things like the System.IO namespace and file watchers, which is basically what you need for the task at hand ( watch a folder, when a file is created or changed, copy it to the backup folder with System.IO.File.Copy )
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
i am using visual basic c# which includes both ... anyway thanks for your suggestion
|
|
|
|
|
weirdsteve wrote:
Forum: C#
Subject: Re: c# back up program ? :S
Sender: weirdsteve
Date: Thursday, September 17, 2009 7:14 PM
i am using visual basic c# which includes both
There is no such thing. What I mean is, you're using a VB Express Edition or a C# express edition ( although you may have both installed ), and either way, you're using VB or C# in your project, not both. you should choose one and stick to it if you're learning, don't go back and forth, it will only confuse you.
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
what i mean is i am using visual c# express and coding the buttons etc ... the buttons and features come from the toolbox in the designer view , then the c# comes in the coding feature ..
|
|
|
|
|
EliottA wrote: and you would get ... as the second hit (the first is your thread)
Yeah, I've noticed that too. There was a time the answer to most questions was in the first hit; Chris must have done something wrong since now the first hit usually returns a question, not an answer.
Luc Pattyn
Have a look at my entry for the lean-and-mean competition; please provide comments, feedback, discussion, and don’t forget to vote for it! Thank you.
Local announcement (Antwerp region): Lange Wapper? Neen!
|
|
|
|
|
It wasn't meant to be kind. It was meant to point out how incompetent you are and that you could very easily have done this for yourself and not bothered us or shown your ignorance.
only two letters away from being an asset
|
|
|
|
|
well if u didn't want bothering , just carry on , i only asked because i didn't know what it was called ... if you don't want to share your knowledge then why the hell are you on a forum ?
|
|
|
|
|
You don't get it, telling you
back up program = copying files
is not sharing knowledge, it's encouraging stupidity.
|
|
|
|
|
obviously back up means copy , but maybe it was advanced , maybe basic , all u had to say is search this or give an example to share what you know .... i am not in the wrong here , as i asked a simple question that anyone with any kindness would think to themselves and say " well maybe i can give him a bit of help and steer him in the right direction" .... i did try and search my term of back up program but failed ...
|
|
|
|
|
Well you managed to make a lot of friends today didn't you
|
|
|
|
|
This is a common Question. I have given the code many times. Go yo Search Messages and Search for post by me and one of them there is a Code for Backup and restore.
Vuyiswa Maseko,
Few companies that installed computers to reduce the employment of clerks have realized their expectations.... They now need more and more expensive clerks even though they call them "Developers" or "Programmers."
C#/VB.NET/ASP.NET/SQL7/2000/2005/2008
http://www.vuyiswamaseko.com
vuyiswa@its.co.za
http://www.itsabacus.co.za/itsabacus/
|
|
|
|
|
I have not used foreach before but I know that the foreach method in what I am trying to do will simplify things emensely. I can adapt after I can see a example.
What I want to do is this:
I have an List<string> of 10 objects so lets call List<string> MyList
foreach (int i = <odd number=""> in MyList.count)
{
Messagebox(Mylist[i])
}
So in the above example It would output 1,3,5,7,9. How would I do this?
Another side point if foreach work not like the above example but like how my other theory is All the ODD number increments will contain "%" the percent sign. But the even values will contain only letters a-z and 0-9.
I don't want to have to do it the way I know how which is double incrementing...
For (i = 0; i < MyList.count; i++)
{
do work
i++
}
|
|
|
|
|
Foreach doesn't loop through the possible indices, but the elements itself... In your first example, you'd actually want something like:
foreach (int i in MyList)
Messagebox(i);
Assuming MyList is a list of integers... You're looping through the contents, not the indices.
In your second example, foreach wouldn't really help, as it's designed to operate on one element at a time, with no knowledge of the next one... You want a plain old "for," but the trick is to remember the syntax:
for ([initializer]; [condition]; [step])
The "step" part doesn't necessarily have to be just incrementing... You could do this:
for (int i = 0; i < MyList.Count; i += 2)
...to work with every other element in the list.
|
|
|
|
|
I appreciate everyone's help here.
To get a better Idea of what I am really trying to do is this:
I receive a path that in a string.
The path contains %USERNAME% in it.
So I need to convert the %USERNAME% to the users login name that windows identifies say "mgeorge"
So in the example c:\apple\%username%\MDB
would become: C:\apple\mgeorge\MDB
Which if I was using dos scripts this would easily work.
But I can't find a easy way of doing this conversion. If there is a simpler way please help me understand.
So I decided I could do something like this as my work around.
I would create a list...
private List<string> IO_SystemVariables()<br />
{<br />
List<string> IO_SystemVariables = new List<string>();<br />
IO_SystemVariables.Add("%USERNAME%");<br />
IO_SystemVariables.Add(Environment.UserName.ToString());<br />
IO_SystemVariables.Add("%MACHINENAME%");<br />
IO_SystemVariables.Add(Environment.MachineName.ToString());<br />
return IO_SystemVariables;<br />
}<br />
The loop thru that list to apply the changes to the string
say something like this:
private static string IO_CheckForSystemVariablePath(String MyPath)<br />
{<br />
List<string> io_SystemVariables = IO_SystemVariables();<br />
for (int i = 0; i < io_SystemVariables.Count; i += 2)<br />
{<br />
if (MyPath.IndexOf(io_SystemVariables[i], 0) > 0)<br />
{<br />
return MyPath.Replace(io_SystemVariables[i],io_SystemVariables[i + 1];<br />
}<br />
<br />
}<br />
<br />
}
Well the code should be close enough to what I was trying to do.
Since every the list 0,2,4,etc will be a variable and the 1,2,5,etc will be it's conversion I figured I would experiment with the foreach loop that I never have been able to figure out.
But if there is an even better way of handling this issue than what I have layed out I am all ears.
|
|
|
|
|
|
just as an example to in code...
Logged in Account username variable = mgeorge
string MyPath = "C:\Apple\%username%\Pictures"
string MyNewPath = Environment.ExpandEnvironmentVariables(MyPath);
the MyNewPath would return me the result "C:\Apple\mgeorge\Pictures"
is this correct if the code is exactly stated above?
I will try it.
|
|
|
|
|
Ok let me throw something else into the equasion
how would I check for if a valid variable Exists before passing the variable?
Would I do option A or B? If neither than what?
Option A)
if (Directory.Exists(Environment.ExpandEnvironmentVariables(MyPath))
{}
else
{}
Should I put option A in a try catch phrase?
Option B)
if (MyPath.IndexOf("%",0) > 0)
{
MyNewPath = Directory.Exists(Environment.ExpandEnvironmentVariables(MyPath)
}
|
|
|
|
|
JollyMansArt wrote: how would I check for if a valid variable Exists before passing the variable?
If you have to do that, then I suggest enumerating the environment variables, populating a Dictionary with the names and values, and using Contains to test whether or not the name exists.
But...
What are you going to do if it doesn't exist?
What if the variable name is embedded among other things or is recursive or something?
There may be times when you need to do that, and the technique will likely be useful in other situations, but it seems (to me) that what you want in this case is ExpandEnvironmentVariables.
|
|
|
|
|
My suggestion would be to use a Dictionary instead of a list.
Dictionary<string,string> IO_SystemVariables = new Dictionary<string,string>();
IO_SystemVariables.Add("USERNAME", Environment.Username.ToString());
...
return IO_SystemVariables;
And in your check/replace:
foreach (string key in io_SystemVariables.Keys)
{
string replaceText = string.Format("%{0}%", key);
if (MyPath.Contains(replaceText))
MyPath = MyPath.Replace(replaceText, io_SystemVariables[key]);
}
Basically, this creates a lookup, so you can plug in a key and get a value... In this case, plug in "USERNAME" and get the username you entered. You can use foreach to loop through all of the keys you've defined, then replace each of them. I added a little code to add the percent signs in the loop, to remove some redundancy in the entry.
Technically using a List is more efficient in this case, but a Dictionary is more readable and understandable.
|
|
|
|
|
if you need a list of translations, say a1->a2, b1->b2, c1->c2, ...
then instead of adding a1, a2, b1, b2, c1, c2, ... to a simple list
add (a1, a2), (b1, b2), (c1, c2), ... to either a simple list (that would take some class or struct to hold two items), or to a dictionary.
The net result would be you can iterate the entire collection (and use a foreach), you don't have to skip every other entry.
Dictionary<string,string> dict=new Dictionary<string,string>();
dict.Add("%USERNAME%", Environment.UserName);
dict.Add("%MACHINENAME%", Environment.MachineName);
...
foreach(string key in dict.Keys) s=s.Replace(key, dict[key]);
BTW: don't use ToString() on something that already is a string!
PS: letting Windows do the substitutions, as PIEBALD showed you, is the better approach in this case.
Luc Pattyn
Have a look at my entry for the lean-and-mean competition; please provide comments, feedback, discussion, and don’t forget to vote for it! Thank you.
Local announcement (Antwerp region): Lange Wapper? Neen!
modified on Thursday, September 17, 2009 7:37 PM
|
|
|
|
|
JollyMansArt wrote: foreach (int i = in MyList.count)
{
Messagebox(Mylist[i])
}
foreach(object o in MyList)
{
MessageBox(o);
}
That's the whole point of foreach, you don't have to use an index to look anything up.
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
RTFM[^]
In the second piece of bad code you present; use i+=2 to increment by two.
|
|
|
|
|
You know, we get our share of morons around here, but this guy seems to me to have asked a reasonable question, albeit one that is indeed well covered in any online example you might find.
PIEBALDconsult wrote: In the second piece of bad code you present; use i+=2 to increment by two.
I believe his point is entirely that if you increment i inside a for loop, the loop also increments it, creating a jump of 2. That evaluation is correct.
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|