user1970661
user1970661

Reputation:

Batch file: How to find the newest version of a file in a directory that has many subfolders?

Details:

I want to search in directory 'A', for a file: 'file.jar' However, directory A does not have any files directly. Instead, it is composed of over 100 subfolders: 'a1', 'a2', 'a3', 'a4', 'a5', etc.

Each subfolder has a some version of 'file.jar' How can I search and copy the newest version?

Upvotes: 0

Views: 174

Answers (1)

John McCarthy
John McCarthy

Reputation: 5972

Here's a starting point: consider using FOR /R for looping through all files recursively in a directory. A brief overview is available at ss64. Also see Rob van der Woude's page on reading file properties in a for loop. Both sites are excellent scripting resources.

For example, the following command will list all files starting with 'a' (case insensitive) in directory C:\A and each file's last-modified date,

FOR /R C:\A %%G IN (a*) DO @ECHO %%G %%~tG 

However, finding the file version itself is a bit more tricky. See How do I retrieve the version of a file from a batch file on Windows Vista?

Upvotes: 2

Related Questions