Link to home
Start Free TrialLog in
Avatar of E=mc2
E=mc2Flag for Canada

asked on

Script that monitors change in a file compared to the next

I have a directory at C:\Users\ProgramFiles\Prg

In this directory 1 Excel file is created every day but at different time every day.

The excel files similar to this, in this format:
11,14,2020.xls
11,13,2020.xls
11,12,2020.xls


I would like a script that I can put on a schedule that will occasionally check this directory, and when it sees another .xls file in this directory, it will create a text file called newfile.txt.

So in this case and in this sequence when the script is triggered if it sees a new file, in this case it will be called 11,15,2020.xls, then it will write a text file in the same directory called newfile.txt.
If the newfile.txt file is present it will simply overwrite it.

Can this be done in .batch or Powershell?
If yes can someone assist me with a script like this?
Thanks in advance. 
Avatar of HainKurt
HainKurt
Flag of Canada image

I read 3 times and could not get what you want...
maybe time to sleep or get a coffee :)
Avatar of E=mc2

ASKER

Very simply whenever a new .xls file appears (regardless of the name of the file) - I want to the script to write a text file called newfile.txt in the same directory
here

$n = ( Get-ChildItem -Filter *.xlsm | Where-Object{$_.LastWriteTime -lt (Get-Date).AddDays(-1)} | Measure-Object ).Count;
if (-NOT  ($n -eq 0)) {
  New-Item -Path . -Name "newfile.txt" -ItemType "file" -Value "New excel file found..."
}

Open in new window

you can add "-path path_of_folder_to_check" to the first line...
and also you can change the path in 3rd line to the same path...
Avatar of E=mc2

ASKER

HainKurt, thanks very much however nothing happens when I run this... 
ASKER CERTIFIED SOLUTION
Avatar of HainKurt
HainKurt
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial