DOS Check for file type

terencevs

Senior Member
Joined
May 12, 2006
Messages
780
I would like to check in a directory if a specific file type exists. The file name changes all the time.

Is it possible to do this in dos with the IF command or is there another way?
 

davemc

Executive Member
Joined
Apr 8, 2009
Messages
6,518
How does the file know what file type it is?

The norm always used to be that files of different types usually use a different extension appended to the end of the file to represent type.
e.g. .doc , .pdf , .exe
 

terencevs

Senior Member
Joined
May 12, 2006
Messages
780
I have an application that writes out a crash file but each file has a different name but the file extension is always the same. So what i want to do is create a batch file that can copy or detect when the file type exists.
 

Drone 42

Senior Member
Joined
Oct 4, 2005
Messages
741
Hope I'm understanding this rite and my dos is a bit rusty but i will use something like this

in the directory just use

dir *.file type
e.g. dir *.exe
 

dequadin

Expert Member
Joined
May 9, 2008
Messages
1,434
You'd have to run the batch file as a scheduled task (or similar) to make it automated.

Why not write a very lightweight .NET service and use the FileSystemWatcher to monitor the directory?
 

terencevs

Senior Member
Joined
May 12, 2006
Messages
780
You'd have to run the batch file as a scheduled task (or similar) to make it automated.

Why not write a very lightweight .NET service and use the FileSystemWatcher to monitor the directory?

Cool thanks for the idea. Will need to refresh my limited C# knowledge! :)
 

dequadin

Expert Member
Joined
May 9, 2008
Messages
1,434
Cool thanks for the idea. Will need to refresh my limited C# knowledge! :)

No worries, the reason I suggest that is because a batch file could become more effort than it's worth. You'll need to some detect the the crash file is new (maybe compare to a previous list) which means you'll need to store that list somewhere (text file) etc etc

Here's what I'm talking about:
FileSystemWatcher Class (MSDN)
Monitoring File System using FileSystemWatcher Class - Part 1

Just create a new project of type "Windows Service" and Visual Studio puts all the bits in for you. I suggest you start off with a Console Application, get everything working and then port it to a Service project. Debugging service projects can be a pain.
 

terencevs

Senior Member
Joined
May 12, 2006
Messages
780
No worries, the reason I suggest that is because a batch file could become more effort than it's worth. You'll need to some detect the the crash file is new (maybe compare to a previous list) which means you'll need to store that list somewhere (text file) etc etc

Here's what I'm talking about:
FileSystemWatcher Class (MSDN)
Monitoring File System using FileSystemWatcher Class - Part 1

Just create a new project of type "Windows Service" and Visual Studio puts all the bits in for you. I suggest you start off with a Console Application, get everything working and then port it to a Service project. Debugging service projects can be a pain.

THANKS!!! Will let you know how it goes!
 
Top