Need help creating a .bat or .vbs script?

November 26, 2010 at 10:16:37
Specs: Windows XP
I need to use a .bat or .vbs file to find the most recent copy of a file in a directory. But this file could be in any given subdirectory of this one folder.

For example. I have a program named "ApplixSearch.exe". It is located in a subdirectory off of "C:\Documents and Settings\username\Local Settings\Apps\2.0\". Sometimes it can be in "C:\Documents and Settings\username\Local Settings\Apps\2.0\7QXWRE45.536\G4293EMJ.PVY\appl..tion_eae9381bf051c1de_0003.0000_64545d69ad1db949\" and sometimes in "C:\Documents and Settings\username\Local Settings\Apps\2.0\7QXWRE45.536\G4293EMJ.PVY\appl..tion_eae9381bf051c1de_0003.0000_63563df2b1954709\".

These smaller directories can change but it is always in a subdirectory off of "C:\Documents and Settings\username\Local Settings\Apps\2.0\". Can anyone help me write a batch or script to find this file and execute it? I am working on all Windows XP and up machines.

Thank you
Corey


See More: Need help creating a .bat or .vbs script?

Report •

#1
November 26, 2010 at 12:14:29
Run this and post the output.

======================================
@echo off > newfile & setLocal enableDELAYedeXpansion

for /f "tokens=* delims= " %%a in ('dir/b/s/a-d/od *.') do (
echo.%%~Ta %%a
)


=====================================
Life is too important to be taken seriously.

M2


Report •

#2
November 26, 2010 at 12:33:20
I put this in a .bat file and I get file called "newfile" with no extension and no data in it. I have the .bat file on the desktop currently, which is also where the newfile was placed.

Thanks


Report •

#3
November 26, 2010 at 12:40:47
And the output is?


=====================================
Life is too important to be taken seriously.

M2


Report •

Related Solutions

#4
November 26, 2010 at 12:45:37
There is no output. Just an empty file named "newfile"

Report •

#5
November 26, 2010 at 18:02:56
Corey, put a pause after the loop and read what it actually says in the window.

Can I put a question here?


Report •

#6
December 8, 2010 at 06:23:39
OK sorry it took so long to test, I was out on vacation all last week and getting caught up on work. I tried putting in the pause and also added the needed filename to search for. When the batch file is ran from a parent directory of the location where the file called ApplixSearch.exe is located at it will find the 2 files. Here are those results:

11/03/2010 02:58 PM C:\Documents and Settings\username\Local Settings\Apps\2.0\7QXWRE45.536\G4293EMJ.PVY\appl..tion_eae9381bf051c1de_0003.0000_63563df2b1954709\ApplixSearch.exe
11/08/2010 12:58 PM C:\Documents and Settings\username\Local Settings\Apps\2.0\7QXWRE45.536\G4293EMJ.PVY\appl..tion_eae9381bf051c1de_0003.0000_64545d69ad1db949\ApplixSearch.exe
Press any key to continue . . .

So two things need to occur now. The batch file needs to be able to search in a specific directory and its subdirectories. I need the batch file to be located in "C:\Documents and Settings\username\RunMe\ApplixSearch" and then find the newest "ApplixSearch.exe" in the above directories, which are not under the RunMe directory.

Next I need the batch file to launch the "ApplixSearch.exe" program.
Here is my current batch file:

@echo off > newfile.txt & setLocal enableDELAYedeXpansion
for /f "tokens=* delims= " %%a in ('dir/b/s/a-d/od ApplixSearch.exe') do (
echo.%%~Ta %%a
)
pause


Thanks for the help.


Report •

#7
December 8, 2010 at 06:41:10
Ignoring for a moment the berserk "02:58 PM", if the date is MM/DD/YYYY you're out of luck.


=====================================
Life is too important to be taken seriously.

M2


Report •

#8
December 8, 2010 at 07:00:46
MM/DD/YYYY I am assuming is the way the DOS commands are showing the date string. What were you expecting to see, or wanting to see?

Report •

#9
December 9, 2010 at 09:49:05
Is there exactly one copy of "ApplixSearch.exe" in these folders, or could there be an arbitrary amount? If it's the former, we're going about it wrong. If it's the later, someone will probably need to use VBScript.

How To Ask Questions The Smart Way


Report •

#10
December 13, 2010 at 11:33:42
There is exactly one copy in one of the sub folders. Here is some more background with the problem I am facing. Another employee at work has created a type of portable application in some way, that when launched from an internal web page it will download the latest version of the ApplixSearch.exe file. This ApplixSearch.exe file is basically a small program that queries DB records and displays them to the end user with whatever filters the user selected.

The problem I am facing is that the ApplixSearch.exe file when downloaded does not overwrite the current version and instead creates a new series of directories in the "C:\Documents and Settings\username\Local Settings\Apps\2.0\". As seen in my above posts. So the directory can change but the name of the application is always ApplixSearch.exe. So I am trying to find the newest version of the file on the PC and then launch that; from a batch file or vbs script.

Any help would be greatly appreciated.
Thanks everyone.


Report •

#11
December 13, 2010 at 12:46:21
@echo off & setLocal EnableDELAYedeXpansion

pushd "C:\Documents and Settings\username\Local Settings\Apps\2.0\"
set N=
for /f "tokens=* delims= " %%a in ('dir/b/s ApplixSearch.exe') do (
set /a N+=1
copy "%%a" "%temp%\!N!.app" > nul
)

for /f "tokens=* delims= " %%a in ('dir/b/s/o-d %temp%\*.app') do (
copy "%%a" d:\ApplixSearch.exe > nul
goto :done
)
:done
del "%temp%\*.app"


=====================================
Life is too important to be taken seriously.

M2


Report •

#12
December 14, 2010 at 06:00:44
Mechanix2go, I unfortunately get no results with the above batch file. I put pauses in different spots within the file and a have no outputted results from the command prompt. I have tried leaving the path to look into as "C:\Documents and Settings\baumanco\Local Settings\Apps\2.0\", which is my logon directory. As well i tried it with "%userprofile%\Local Settings\Apps\2.0\". Neither have yielded any results. Thoughts?

My handle on gChat is corey.bauman if this would be easier than the forum page.


Report •

#13
December 15, 2010 at 03:12:37
Did you get this file: d:\ApplixSearch.exe ?

If you have no d drive change d: to c: and try again.


=====================================
Life is too important to be taken seriously.

M2


Report •

Ask Question