So I am attempting to change the creation date of a text file in C#. The user will type in thr creation date of the file, it will then change the text files creation date to what the user inputted. Trouble is it keeps adding a ' for some reason resulting in an error message, it is calling on Powershell to accomplish this:
public partial class Form6 : Form
{
public Form6()
{
InitializeComponent();
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
string dir = textBox1.Text;
PowerShell ps = PowerShell.Create();
ps.AddCommand("Get-ChildItem c:\\encryptedmessagehere.txt | % {$_.CreationTime = '"+ dir + "'}");
ps.Invoke();
}
}
}
Trouble is, after the "'}");, it automatically adds another ', incorrecting the powershell command to change the date. Is there a way to stop it from adding the ' at the end?
The returned error is:
System.Management.Automation.CommandNotFoundException HResult=0x80131501 Message=The term 'Get - ChildItem C:\encryptedmessagehere.txt | % {$_.CreationTime = '06/12/12 09:27:03 AM'} ' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
Thank you.
Get - ChildItem<- this is your (first, if not only) problem, it should beGet-ChildItemwithout any spaces.FileInfoobject and using that to update the date?