I need to create a vbs to sort a seteable number of files (only the files) by the modified date in a folder with subfolders, and print the file with the absolute path, like this:
The vbs:
Dim MAX
Dim Folder
MAX = 100
Folder = "C:\Test"
vbscript functions to group all files of all subfolders, and sort them by MOD date... ok
vbscript funciont to make a text file output (This i can't do it by myself)
end
The text file output (100 newest files):
c:\newest 1st file.txt
c:\subfolder1\newest 2nd file.txt
c:\subfolder7\newest 3rd file.txt
c:\subfolder2\newest 4 file.txt
c:\subfolder8\newest 5 file.txt
c:\subfolder4\newest 6 file.txt
c:\subfolder2\newest 7 file.txt
c:\newest 8 file.txt
c:\subfolder3\newest 9 file.txt
etc...
Really no matther if the solution can it be done with Batch, I agree, But i’ve tried this:
Dir /S /TC /O-D
And the only problem is that don’t show me the absolute path…
EDIT: Oh, and ofcourse I’ve tried:
Dir / B / S / TC / O-D
But the /B parameter implies a GREAT difference on the command that I said before …
I mean:
Dir / S / TC / O-D
The command groups (together) all files in all subdirectories and sorts them by date. (GOOD!)
Dir / B / S / TC / O-D
The command going procesing folder by folder and ordering each file, and showing it. (BAD!)
So, if i need to sort neswest only 100 files, And if i use Batch dir command with “/B” parameter, i get this:
Output:
(Position 1) c:\subfolder1\Newest 1st file of this folder.txt
(Position 2) c:\subfolder1\Newest 2nd fil eof this folder.txt
(Position 3) c:\subfolder1\Old file of this folder.txt
(Position 3) c:\subfolder1\Older file of this folder.txt
(Position 4) c:\subfolder1\Oldest file of this folder.txt
(Position 5) c:\subfolder2\Newest 1st file of this folder.txt
(Position 6) c:\subfolder2\Newest 2nd file of this folder.txt
(Position 7) c:\subfolder2\Old file.txt
etc ...
So please don’t tell me nothing about use dir with /B parameter, i know it good :(.
thanks again
You can do it with
forcommand and ~ syntax (seefor /?):The use of brackets allows for single redirection od whole
fortosort. Without brackes everyechowould be redirected to individualsort, so no sorting would be done.EDIT: As Ekkehard.Horner pointed out, the above code will work only in regions where dates are printed in yyyy-mm-dd format. In a region where dates are printed in mm/dd/yyyy format, you can use the following batch file:
I did not manage to repeat the trick with brackets inside a batch file, so the script calls itself with a parameter causing it to print the list of files and then sorts the output. The dates are converted to yyyy-mm-dd format by using
%variable~:start-length%syntax (seeset /?) and delayed variables expansion. It is not as bullet-proof as dbenham’s solution, but it works.