Batch file to open windows explorer to last created file

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Message
Author
berserker
Posts: 95
Joined: 18 Dec 2013 00:51

Re: Batch file to open windows explorer to last created file

#31 Post by berserker » 29 Dec 2013 21:29

foxidrive wrote:/O will sort only within a folder. It doesn't sort a folder tree.


how about this, just a quick one to get the idea across

Code: Select all

dir /s /o:d /T:C /q | findstr "user2" | sort 

then get the last line

TS just want the file, not a folder. In fact,
gibsongk55 wrote: I need to create a batch file that will open windows file explorer to the last file created (not folder but file) and also check against the owner so that the owner = user2,


or am i missing something?

gibsongk55
Posts: 13
Joined: 27 Dec 2013 22:26

Re: Batch file to open windows explorer to last created file

#32 Post by gibsongk55 » 29 Dec 2013 23:09

foxidrive wrote:Try this on some sample files:

When it prompts you to delete the file, pressing Enter will bypass the deletion. Typing y and enter will delete the file.

The first three lines contain items for you to set.



Thank you. This seems to do the trick. Will have to test with more files and see how it does for speed. Thanks again.

Gibs

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Batch file to open windows explorer to last created file

#33 Post by foxidrive » 29 Dec 2013 23:10

berserker wrote:
foxidrive wrote:/O will sort only within a folder. It doesn't sort a folder tree.


how about this, just a quick one to get the idea across

Code: Select all

dir /s /o:d /T:C /q | findstr "user2" | sort 

then get the last line


You try that and see if it works.

TS just want the file, not a folder. In fact,
gibsongk55 wrote: I need to create a batch file that will open windows file explorer to the last file created (not folder but file) and also check against the owner so that the owner = user2,


or am i missing something?


Yes, you are. My code returns the file.

The /O will not sort all the files in a folder tree. It only sorts within a folder.

berserker
Posts: 95
Joined: 18 Dec 2013 00:51

Re: Batch file to open windows explorer to last created file

#34 Post by berserker » 30 Dec 2013 00:00

foxidrive wrote:No. It has to descend through a folder tree and get the latest file amongst them all.

/s descends folder
/T:C show with creation date
/q: display user

findstr "user2" will only get those lines that contains "user2"
the first column which is the date, can be sorted . Depending on sort order, its either the first line or last line. That's the line we need


foxidrive wrote:The /O will not sort all the files in a folder tree. It only sorts within a folder.


well in fact it doesn't matter as findstr "user2" will find all files own by user2 first. /s should already give you those also in subfolders.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Batch file to open windows explorer to last created file

#35 Post by foxidrive » 30 Dec 2013 03:53

foxidrive wrote:
berserker wrote:how about this, just a quick one to get the idea across

Code: Select all

dir /s /o:d /T:C /q | findstr "user2" | sort 

then get the last line


You try that and see if it works.

Post Reply