Batch code that will print a list of what is inside the "Recent Items" folder

149 views Asked by At

I am trying to get a batch code to print the just the Date Modified, and Name of each file (more properties are ok, I just need those two) in the "Recent Items" folder. I have tried a few codes but sadly it will not work, any direction would be greatly appreciated.

2

There are 2 answers

11
npocmaka On BEST ANSWER

Recent items is located here:

%userprofile%\Appdata\Roaming\Microsoft\Windows\Recent

But it contains only links (.lnk files ) to the recent opened items. So

dir /o:d /t:c   "%userprofile%\Appdata\Roaming\Microsoft\Windows\Recent"

Will list them but it will be hard to distinguish files form directories.

Here's how you can get more info with WMIC query (could be slow):

WMIC DATAFILE WHERE "PATH='\\Users\\username\\Appdata\\Roaming\\Microsoft\\Windows\\Recent\\'  " GET LastAccessed, LastModified, Name, FileSize
0
JosefZ On

Taking regard to all chat-like discussion:

1. To get "recent" folder:

`For /F "tokens=1,2*" %%G in ('reg query "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders" /v recent ^|Find /I "recent"') do @echo G="%%G" H="%%H" I="%%I"` 

and then you could replace that @echo G="%%G" H="%%H" I="%%I" with set "recentfldr=%%I" and continue with dir "%recentfldr%\" etc.

2. To wait until dir command ends (add switches for dir ad libitum but note escaped redirecting operator ^>):

start "" /wait cmd /C dir /s "%recentfldr%\" ^> "%temp%\afile.txt"

3. To send a text file to default printer:

%SystemRoot%\system32\NOTEPAD.EXE /p "%temp%\afile.txt"

Good luck!