Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7807807
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T02:58:11+00:00 2026-06-02T02:58:11+00:00

I need to create a vbs to sort a seteable number of files (only

  • 0

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T02:58:14+00:00Added an answer on June 2, 2026 at 2:58 am

    You can do it with for command and ~ syntax (see for /?):

    (for /r %A in (*) do @echo %~tA %A ) | sort /r
    

    The use of brackets allows for single redirection od whole for to sort. Without brackes every echo would be redirected to individual sort, 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:

    @Echo Off
    setlocal enabledelayedexpansion
    
    if "%1"=="list" goto :list
    %0 list | sort /r
    
    endlocal
    goto :EOF
    
    :list
    for /r %%A in (*) do (
      set t=%%~tA
      echo !t:~6,4!-!t:~0,2!-!t:~3,2! %%A
    )
    goto :EOF
    

    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 (see set /?) and delayed variables expansion. It is not as bullet-proof as dbenham’s solution, but it works.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i need to create a text file named listfile.txt in the folder C:\Documents and
i have vbs file with a few command line utilities that need to be
I need create xls-file with own data. But file may already be created, and
I need to create a .VBS script to reset the Windows local administrator password
I need to read the location of the Temporary ASP.NET Files folder from VBScript
I need create a server side game loop, the problem is how to limit
I need create custom dialog and put JPanel into it. Is it possible?
i need create an email list sending to many emails. what is best solution
I need create clone repository. but I do not know where can I get
I need create a document word with Java. And I ask, how can I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.