File time stamp does not change with data update - windows

I have customer which claims that he has one application which updates the data in log file but that application does not change the time stamp of the log file.
I have question why would any application has such behavior.

It's a new FEATURE of Windows 2008 (R2), Windows 7 and up. Modified time is not updated anymore like it used to in Windows 2003.
http://blogs.technet.com/b/asiasupp/archive/2010/12/14/file-date-modified-property-are-not-updating-while-modifying-a-file-without-closing-it.aspx
And
http://social.technet.microsoft.com/Forums/en-US/winservergen/Thread/2B8BACA2-9C1B-4D80-80ED-87A3D6B1336F

There is a good workaround for build automation:
copy /b <Filename> +,,
I found this trick here: https://superuser.com/questions/292630/how-can-i-change-the-timestamp-on-a-file.
The strange is that "copy /?" does not say about /b option.

I know, this is a very poor C# workaround for some special cases. My server writes a log and I need to get the file changes using a FileSystemWatcher.
So, everytime my log file is updated I create a new empty file with the same name but the extention ".update".
try
{
string updateFlagFile = Path.ChangeExtension(myLogFilename, ".update");
using (File.Create(updateFlagFile))
{ }
}
catch (Exception)
{ }
My FileSystemWatchers tracks this file and I know that the log was updated.

Related

Does Angular CLI prevent timestamp update for *.TS files?

After setting up an Angular 2 program using Angular CLI (following the procedure at https://angular.io/guide/quickstart) and using VS Code (https://code.visualstudio.com/) to work with the files I've noticed that the file timestamps for *.TS files do not get updated. Testing on Windows 10, the problem occurs even if I make a change to a TS file with Notepad and do so immediately after reboot. However, if I copy the TS files to another folder, they show updated timestamps.
When opening other folders, there is an instant display of files, but when opening the app folders with the TS files, there is a delay of several seconds, with a message "Working on it..."
The TS files had been associated with a video processing program ("transport stream" file), but I shifted the association to VS Code, but that didn't fix the problem.
I opened a bug report at https://github.com/Microsoft/vscode/issues/25569 but the VS Code folks could not reproduce the problem, suggesting that it is not seen for many VS Code users. That report is now is some sort of limbo in which it is listed as closed but one can still comment.
So I'm wondering whether the Angular CLI environment prevents timestamp update for the TS files.
Any suggestions on how to get the TS files in an Angular 2 project to show the current timestamp?
Addendum: the problem is not just for ts files. It extends to css files as well, as illustrated in this image in which the file system lists 19 April as the file date for styles.css, but the ToolTip for the file gives the more recent (correct) date:
Clearly some part of this environment is overruling one of 2 displays of the file date.
The problem is not the timestamp; it is the column displayed in Windows Explorer. Instead of the usual "Date Modified" column, "Date" was displayed. I don't think problem is caused by Angular CLI or VSCode. It looks like it is created by the video processing program ("transport stream") file type assignment; removing that file association and assigning *.ts to VSCode prevents the problem from occurring. However, this doesn't fix instances in which it occurred already; here is how to fix those:
In Windows Explorer click View on the menu, then "Add Columns". Uncheck "Date" and check "Date Modified". You may want to remove "Length" as well.

Issues while converting a windows app to windows service

I created a monitoring utility that checks cpu, ram, drive space stats and emails if the usage goes above set threshold. It works great in the system tray but I realized that the exe will stop when I log out of windows server. That led me to believe that I needed to create a windows service. I would like to use the existing GUI Form to save data to application settings and use those settings in windows service. Here are the steps I took so far,
Added a Windows Service class.
Modified the original code to get rid of any interactive items that were related to GUI Form.
Added the code to this class.
Added a Service installer.
Added this code to it-->
public ProjectInstaller()
{
InitializeComponent();
ServiceProcessInstaller serviceProcessInstaller = new ServiceProcessInstaller();
ServiceInstaller serviceInstaller = new ServiceInstaller();
serviceProcessInstaller.Account = ServiceAccount.LocalSystem;
serviceProcessInstaller.Username = null;
serviceProcessInstaller.Password = null;
serviceInstaller.StartType = ServiceStartMode.Automatic;
serviceInstaller.ServiceName = "Server Monitoring";
this.Installers.Add(serviceProcessInstaller);
this.Installers.Add(serviceInstaller);
}
Change Start up object to Utility.Program.
When I try installing this through installUtil I get this error
System.IO.FileNotFoundException: Could not load file or assembly 'file:///C:\Use
rs\AdminUser\Desktop\Temp\Server' or one of its dependencies. The system cannot
find the file specified..
Thanks!
If you are saving these application settings into a file that is in the same directory as the Windows service, that is going to be your problem. All Windows Services are run in the C:/Windows directory (or a sub-directory in there) so when you access files you will need to do one of two things:
Change the executing directory
You can change the 'current directory' for the executing app back to the folder that contains the exe with the following line of code:
System.IO.Directory.SetCurrentDirectory(System.AppDomain.CurrentDomain.BaseDirectory);
This will make all relative files become relative to the executable location once again.
Make all file request full paths
This one is easier for some files than others. System files are the hardest. So if you are trying to get to a .config file, that's going to be a nightmare.

Finding the path to file using application startuppath in a windows form

Hi every one I am trying to access a file in certain folder in my windows form app, but I keep getting the error "could not find a part of the path: C:....e.t.c".
here is my code:
string doc = Application.StartupPath + #"\filefolder\pin-card02.docx";
please what is wrong with this piece of code?
I have seen some explanations but nothing tells me how to direct my program to a certain file in a folder...
Thanks in Advance
There's probably nothing wrong with this piece of code, most likely this file is not set as content of your application and is not getting copied to the output directory, if this is part of a visual studio solution, check that pin-card02.docx has "copy to output directory" set to "Always" or "Copy if newer" in the .doc's properties, if it's not part of the solution, you may need to include it and set the property.
If this doesn't help, you'll need to provide more information on the problem.

AIR- detect directory change Windows desktop

Discovered a class for detecting directory changes but only seems to work on Mac Desktop, NOT Windows.
https://github.com/renz45/Actionscript/tree/master/Air/filesystem
The FileMonitor class only detects changes for single files I believe.
Does anyone know of a way to detect directory changes with AIR on Windows desktop?
The monitor checks for the modification time of folders only. On Windows the folder modification time update behaviour is very unreliable, try to add a new file, you'll probably see that it updates the folders modification time, while it doesn't when changing the contents of a file.
For a more reliable behaviour you would have to check the modification time of all files and subfolders.
Here's an example, a changed DirectoryMonitor.traverseDirectoryTree method which also includes the files. It's not thoroughly tested, and with a growing number of nested files and folders you might run into performance problems, but in the end it's just an example.
private function traverseDirectoryTree(dir:File):Vector.<File>
{
var list:Vector.<File> = new Vector.<File>;
list.push(dir);
for each (var file:File in dir.getDirectoryListing())
{
if(!file.isHidden)
{
list.push(file);
if(file.isDirectory)
{
list = list.concat(traverseDirectoryTree(file));
}
}
}
return list;
}
See also
Rules for "Date Modified" of folders in Windows Explorer
Folders last modified time stamp are not updated in Windows 7

What overwrites the <executble-name>.exe.config file with the original App.config at the end of debugging?

In Visual Studio 2010 what overwrites the <executable-name>.exe.config and replaces it with the App.config version of the file when debugging ends?
Is it Visual Studio doing that? Is there any way of toggling this functionality?
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
// ... Modify configuration.AppSettings.Settings by
// running Add/Remove on a couple of keys.
// Write out the <executable-name>.exe.config file...
configuration.Save(ConfigurationSaveMode.Modified);
// Break here and notice that the file has been written to.
ConfigurationManager.RefreshSection("appSettings");
}
Example - Writing out settings on exit
Notice where I break at the end of the _FormClosing handler method.
The Save() method only saves settings whose Scope is user, not Application. Those setting values get written to a user.config file that's stored in a subdirectory of c:\users\name\appdata. It is hard to find, the subdirectory name is a hash based on the application name and version.
Which is the way it has to work, a program doesn't normally have write access to the app.exe.config file after it got deployed. UAC prevents a program from writing to files in c:\program files.
In other words, your app.exe.config is not supposed to change. Look at it with notepad to verify that.

Resources