What I want to do is find .. -path "bin\\.*\\.*\.Drivers\..*\.dll"
But UnxUtils find fails me:
P:\Utils\lib>find .. -name bin
..\Utils.API\bin
..\Utils.Common\bin
..\Utils.Console\bin
..\Utils.Drivers\Driver\bin
..\packages\ini-parser.2.0\bin
P:\Utils\lib>find .. -path bin
P:\Utils\lib>
What I'm doing wrong?
Updated: surprised to find Windows developers thought about it: findstr
P:\Utils\lib>for /f "tokens=* USEBACKQ" %d in (`dir .. /s /b ^| findstr "bin.*\.Drivers\..*\.dll"`) do dir %d
does quite the same as:
$ find .. -ipath "bin.*\.Drivers\..*\.dll" -exec ls {} \;
and is not that much longer.
Related
Trying to find out which users have google chrome by searching the appdata folder of each user for the executable and then a series of actions to take if found. On our system some of the user folders are on a persistent disk, D:. I used a for loop for both instances but I'm sure there is a better way.
If I run it from the computer it seems to work but when ran as a start up nothing seems to happen. Wondering if someone could point out issues or inefficiencies, I know there in there.
#ECHO OFF
SETLOCAL ENABLEDELAYEDEXPANSION
FOR /D %%H IN ("D:\Users\*") DO (
IF EXIST "%%H\appdata\local\google\chrome\application\chrome.exe" (
DEL /Q "%%H\Desktop\Google Chrome.lnk"
msiexec /i "[MSI PATH]" /quiet
ECHO %DATE% %COMPUTERNAME% %%H Replaced >> "ChromeInstalls.txt"
)
)
FOR /D %%G IN ("C:\Users\*") DO (
IF EXIST "%%G\appdata\local\google\chrome\application\chrome.exe" (
DEL /Q "%%G\Desktop\Google Chrome.lnk"
msiexec /i "[MSI PATH]" /quiet
ECHO %DATE% %COMPUTERNAME% %%G Replaced >> "ChromeInstalls.txt"
)
)
EXIT /b
Any help is appreciated.
The problem is that you are parsing invalid path to the for body . Try using /r switch to lock on the parent drive containing the chome file to process all subdirectories inside the specified drive so that you dont have to use a full path in your set () eg ..
#echo off
For /r d: %%a in (*) do (
If "%%~nxa"=="Chrome.exe" (
DEL /Q "%%G\Desktop\Google Chrome.lnk"
msiexec /i "[MSI PATH]" /quiet
ECHO %DATE% %COMPUTERNAME% %%G Replaced >> "ChromeInstalls.txt"
)
)
For /r c: %%a in (*) do (
If "%%~nxa"=="Chrome.exe" (
DEL /Q "%%G\Desktop\Google Chrome.lnk"
msiexec /i "[MSI PATH]" /quiet
ECHO %DATE% %COMPUTERNAME% %%G Replaced >> "ChromeInstalls.txt"
)
)
Try that out . Hpe this helps .
I need a batch script to list .avi|.mp4 and run a command for all directories that contain such files:
mencoder.exe <some_arguments> -o "output/(name_of_directory).mp4" <list_of_files_in_directory_spearated_by_spaces_evey_file_quoted>
Could anybody help me with that? Is it possible at all?
I made a script in PHP, compiled it with BamCompile, but it seems to act totally different on Windows 8, arrays are being converted to strings and something really weird is goin on...
try this:
#echo off &setlocal
cd /d "%userprofile%\Videos"
for /f "tokens=1*delims=:" %%a in ('dir /b /a-d *.avi *.mp4^|findstr /n $') do set "$%%a=%%~b"
setlocal enabledelayedexpansion
for /f "tokens=1*delims==" %%a in ('set "$" 2^>nul') do set "line=!line! "%%~b""
echo mencoder.exe [some_arguments] -o "output/(name_of_directory).mp4" %line%
Look at the output and remove echo if it looks good.
See if this floats your boat. ! characters are verboten in paths and filenames.
#echo off
setlocal enabledelayedexpansion
cd /d "%userprofile%\Videos"
for /f "delims=" %%a in ('dir /s /b /a-d *.avi *.mp4') do (
for /f "delims=" %%b in ("%%~dpa.") do (
set "line="
for %%c in ("%%~dpa*.*") do set line=!line! "%%c"
echo mencoder.exe [some_arguments] -o "output\%%~nxb.mp4" !line!
pause
)
)
When I run the following in cmd prompt, it works fine
pushd "C:\Converter"
for /f "delims=" %g in ('dir "C:\Toconvert" /b /s /ad') do (powershell .\BatchConvert.ps1 "%g" 10)
popd
It executes the command successfully.
This is the output:
C:\Converter>(powershell .\BatchConvert.ps1 "C:\Toconvert\Prego!PDF" 10 )
When I tried running the same command in a .bat file, it fails. Using cmd line to run the bat file I find this is what it is generating:
C:\Converter>for /f "delims=" \Toconvert" /b /s /ad') do (powershell .\BatchConvert.ps1 "g" 10)
Why is it dropping off the "%g in ('dir "C:" before the brackets and why is it dropping off the % in the do command? How do I escape characters to get this to work as a .bat?
% must be doubled as %% when used in batch files – dbenham May 17 '13 at 12:39
How can I customize the the FOR command below to loop through the files inside the Database folder following the order of the number prefixed in the file name?
FOR /R ../Database %%f IN (*.sql) DO sqlcmd -S %1 -d %2 -U %4 -P %5 -i "%%~f" >> Logs/%2_DBInstall.log || goto errors
Database folder contains:
001_usp_procedure1.sql
002_ups_procedure2.sql
Thanks very much,
Please try the following
del temp.txt
del temp1.txt
for /F "usebackq " %%F IN (`dir /b /s /o:n "../Database/*.sql"`) DO (
echo %%~nF / %%F >> temp.txt
)
sort temp.text temp1.text
for /F "tokens=1,2 delims=/" %%i IN (temp1.txt) DO sqlcmd -S %1 -d %2 -U %4 -P %5 -i "%%j" >> Logs/%2_DBInstall.log || goto errors
It should work for recursive directories too (process is sorted by global filename without taking account of the path ... did I understand the problem?)
Please note that two temp files are being used. Be careful with the names (or use real temp files)
for /f %%i in ('someprogram %1 2>&1 | find /c "some string"') do ...
it says
2>&1 was unexpected at this time
You will need to escape special characters within the for command:
for /f %%i in ('someprogram %1 2^>^&1 ^| find /c "some string"') do ...
cmd's parser is not the most robust one; this is unfortunately necessary.