Batch file to open windows explorer to last created file
Moderator: DosItHelp
-
- Posts: 13
- Joined: 27 Dec 2013 22:26
Batch file to open windows explorer to last created file
Hello All,
Just found this forum and was hoping someone could help me out. 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, then highlight the file and delete with a confirmation box to come up for the user to confirm it.
Is this possible? Appreciate any help.
Thanks,
Gibs
Just found this forum and was hoping someone could help me out. 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, then highlight the file and delete with a confirmation box to come up for the user to confirm it.
Is this possible? Appreciate any help.
Thanks,
Gibs
-
- Posts: 208
- Joined: 26 Dec 2013 09:28
- Contact:
Re: Batch file to open windows explorer to last created file
Hi Gibs,
Sure, it's possible.
Little bit explanation
Sure, it's possible.
Code: Select all
for /f %%f in ( 'dir /a-d /o-d /b "%WINDIR%"' ) do (
explorer /select,"%WINDIR%\%%f"
goto 1
)
:1
Little bit explanation
dir - take the listing
/a-d - everything but directories
/o-d - sort by date/time (the newest first)
/b - show filenames only
explorer /select - open a window with the specified object (a file in your case)
goto 1 - stops execution of the loop
-
- Posts: 13
- Joined: 27 Dec 2013 22:26
Re: Batch file to open windows explorer to last created file
Thanks for the explanation. I tried it but I need it to check subfolders and only bring up the latest file not the subfolder itself. Also any idea how to match the owner of the file? For instance I would like the owner = user2 .
Thanks again,
Gibs
Thanks again,
Gibs
Re: Batch file to open windows explorer to last created file
What is the scope of the search?
Are you searching through a lot of files?
Do you need it to be fast?
Are you searching through a lot of files?
Do you need it to be fast?
Re: Batch file to open windows explorer to last created file
Windows Explorer helps you navigate your folder structure. It doesnt open files. So saying you want Explorer to open the last created file does not make sense. Applications open files and there has to be a file type association for it to open automatically.
Re: Batch file to open windows explorer to last created file
Squashman wrote:It doesnt open files. <...> Applications open files <...>.
Yes, it is true, but...
Compare results of execution of these 2 batch files:
Code: Select all
@echo off
copy nul File_with_extension.txt>nul
File_with_extension.txt
exit
Code: Select all
@echo off
copy nul File_with_extension.txt>nul
explorer File_with_extension.txt
exit
There is a difference, but small.
Compare results of execution of other 2 batch files:
Code: Select all
@echo off
copy nul File_without_extension>nul
File_without_extension
exit
Code: Select all
@echo off
copy nul File_without_extension>nul
explorer File_without_extension
exit
There is a big difference.
Thus it is the Windows Explorer is responsible for file type associations.
-
- Posts: 13
- Joined: 27 Dec 2013 22:26
Re: Batch file to open windows explorer to last created file
foxidrive wrote:What is the scope of the search?
Are you searching through a lot of files?
Do you need it to be fast?
Searching one directory with approximately 200 subfolders and one or two files in each.
Yes it has to be fast.
-
- Posts: 13
- Joined: 27 Dec 2013 22:26
Re: Batch file to open windows explorer to last created file
Squashman wrote:Windows Explorer helps you navigate your folder structure. It doesnt open files. So saying you want Explorer to open the last created file does not make sense. Applications open files and there has to be a file type association for it to open automatically.
I don't want to open the file. I only want to find the last file created checking all subfolders and have windows explorer bring the file up and if possible delete it leaving me with a confirmation box to delete it.
If not possible at least find the last created file and bring it up in windows explorer.
Re: Batch file to open windows explorer to last created file
gibsongk55 wrote:Squashman wrote:Windows Explorer helps you navigate your folder structure. It doesnt open files. So saying you want Explorer to open the last created file does not make sense. Applications open files and there has to be a file type association for it to open automatically.
I don't want to open the file. I only want to find the last file created checking all subfolders and have windows explorer bring the file up and if possible delete it leaving me with a confirmation box to delete it.
If not possible at least find the last created file and bring it up in windows explorer.
you can ask for deletion confirmation using
del /p
and why do you need to open windows explorer?
-
- Posts: 13
- Joined: 27 Dec 2013 22:26
Re: Batch file to open windows explorer to last created file
berserker wrote:gibsongk55 wrote:Squashman wrote:Windows Explorer helps you navigate your folder structure. It doesnt open files. So saying you want Explorer to open the last created file does not make sense. Applications open files and there has to be a file type association for it to open automatically.
I don't want to open the file. I only want to find the last file created checking all subfolders and have windows explorer bring the file up and if possible delete it leaving me with a confirmation box to delete it.
If not possible at least find the last created file and bring it up in windows explorer.
you can ask for deletion confirmation using
del /p
and why do you need to open windows explorer?
So I can run a batch file quickly with one click and have it find the last created file and display it in windows explorer. Then I can confirm by sight if it is the one I want to delete. The purpose of the batch file would be to find the last created file within subfolders and bring it up in windows explorer. So this is what I would like to set up. Thanks.
Re: Batch file to open windows explorer to last created file
gibsongk55 wrote:So I can run a batch file quickly with one click and have it find the last created file and display it in windows explorer. Then I can confirm by sight if it is the one I want to delete. The purpose of the batch file would be to find the last created file within subfolders and bring it up in windows explorer. So this is what I would like to set up. Thanks.
go to Start , Run, type cmd
cd to your directory where you keep the batch
run the batch which will display the last created file for you
confirm delete because the batch already coded with del /P
press enter
end of story.
what's the point windows explorer?
-
- Posts: 13
- Joined: 27 Dec 2013 22:26
Re: Batch file to open windows explorer to last created file
berserker wrote:gibsongk55 wrote:So I can run a batch file quickly with one click and have it find the last created file and display it in windows explorer. Then I can confirm by sight if it is the one I want to delete. The purpose of the batch file would be to find the last created file within subfolders and bring it up in windows explorer. So this is what I would like to set up. Thanks.
go to Start , Run, type cmd
cd to your directory where you keep the batch
run the batch which will display the last created file for you
confirm delete because the batch already coded with del /P
press enter
end of story.
what's the point windows explorer?
Because it is easier and faster to run the batch file from a shortcut on the desktop. Not end of story. The code will not search subfolders. So the batch file does not find the last created file. Furthermore I need the batch file to check ownership. So the owner of the file must equal "user2". I need the batch file to do this as well.
Re: Batch file to open windows explorer to last created file
gibsongk55 wrote:So I can run a batch file quickly with one click and have it find the last created file and display it in windows explorer. Then I can confirm by sight if it is the one I want to delete. The purpose of the batch file would be to find the last created file within subfolders and bring it up in windows explorer. So this is what I would like to set up. Thanks.
The workaround I had planned was to provide a VBscript message box wth the file details and a prompt for deletion.
It may be slow as the batch file has to get the file details of every file belonging to the user, arrange them in a way that can be then sorted to get the latest file, and then show
a window with the details.
You can't get Explorer to display a file for deletion AFAIK.
-
- Posts: 13
- Joined: 27 Dec 2013 22:26
Re: Batch file to open windows explorer to last created file
foxidrive wrote:gibsongk55 wrote:So I can run a batch file quickly with one click and have it find the last created file and display it in windows explorer. Then I can confirm by sight if it is the one I want to delete. The purpose of the batch file would be to find the last created file within subfolders and bring it up in windows explorer. So this is what I would like to set up. Thanks.
The workaround I had planned was to provide a VBscript message box wth the file details and a prompt for deletion.
It may be slow as the batch file has to get the file details of every file belonging to the user, arrange them in a way that can be then sorted to get the latest file, and then show
a window with the details.
You can't get Explorer to display a file for deletion AFAIK.
Okay how about skip the deletion. Is there a way to have windows explorer display the last created file and check the owner?
Re: Batch file to open windows explorer to last created file
You can have a script open up Windows Explorer to a specific folder but you would need a batch file or vbscript to display the file owner.