Hot answers tagged

5

Batch scripts have a few variables they can use to get special information about the script. %1 to %9 are the parameters that were used after calling the batch script, but %0 is the full path including the filename itself of the batch file. So if the batchfile is stored on the desktop, %0 would be: c:\users\user\Desktop\test.bat Given that %0 gives us this ...


3

How do I remove spaces from a variable? If you are going to use for or if (which have expressions using brackets) then you would need to use Delayed Expansion. However there is a much easier solution that removes the spaces all at once: @echo off setlocal set "X=I am good" set _result=%X: =% echo %_result% endlocal An A-Z Index of the Windows CMD ...


2

Iterate over all files or directories: for %%i in (*.html) do ... for /d %%i in (*_files) do ... Note: In .bat scripts you must use %% for the iterator variable, while the interactive shell uses only a single %. Remove a file extension (only works with iterators, not variables): %~ni, %~xi for %%f in (*.html) do echo %%~nf_files Replace a substring (only ...


1

The problem is that if the first parameter to START is a quoted string, it will assume that it is the intended title. If you need to pass a quoted string for the executable because of spaces in the pathname, put an empty string "" as the first parameter to START: START "" "C:\Program Files\Mozilla Firefox\firefox.exe" Editorial ...


1

A solution I hadn't initially considered before I posted this question is to check the file exists before calling start, as follows: if exist example.exe ( start example.exe ) else ( echo Error: 'example.exe' does not exist 1>&2 ) Strictly speaking, not a direct answer to my question as I originally stated it, but nonetheless serves my ...


1

Ok so it took me a while but i found this and it worked perfectly fine @echo off Title Download code from pastebin and display it with batch Set "url=https://pastebin.com/raw/vzx1dEdW" for %%# in (%url%) do ( set "File=%tmp%%%~n#.txt" ) Call :Download "%url%" "%File%" If exist "%File%" ( ( Type "%File%&...


1

We're missing a bit of information in this post to construct a proper answer. In any case, Powershell is going to help a lot here. Powershell can do it with just one line of code (or more if you want to go fancy here. Because I don't know the url of the file you want to download, I'll use Chrome as example, and save the file to the download folder in your ...


1

For future reference, the code ComputerUser121212 posted works perfectly. I've made it into a batch file, using the following link as help: https://stackoverflow.com/questions/4571244/creating-a-bat-file-for-python-script I'm not proficient in batch files so my code may be suboptimal, but it works. @echo on rem = """ python -x "%~f0&...


1

The following Python code should do the trick. The code runs on Python 3.9 and uses PDFtk. It assumes the first file in your directory is one that contains "Microsoft Outlook" import os files = os.listdir(".") files.sort() command_prefix = "pdftk " command_args = "" command_end = "cat output output1.pdf" ...


1

It look like a bug in the color conversion algorithm, but I can't be sure. When replacing -pix_fmt yuv420p with -pix_fmt yuv444p the colors are the same as the direct conversion. The color conversion path: Bayer -> yuv420p modifies the colors. The color conversion path: Bayer -> yuv444p works correctly. The common Demosaicing algorithms converts from ...


1

One line version using operator && or || if exist/not exist: >nul 2>&1 pushd "%cd%\my_Folder" &&(popd & set "Bool=True")|| set "Bool=False" set Bool & echo=%Bool%


1

Batch file programming is messy.  I can’t find any one solution that works perfectly.  But this three-pronged approach seems to work: SET CURR_PATH=%CD% :: Assume/anticipate failure set "FOLDER_EXIST=False" cd /d "%INPUT_PATH%\%REL_PATH%" 2> nul && ( if exist %FOLDER_NAME%\ set "FOLDER_EXIST=True" if ...


1

How do I do it with a single command? Use brackets: @echo off setlocal enabledelayedexpansion @for %%I in ("foo") do ( reg delete "HKLM\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Run" /v "%%~I" /f reg delete "HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Run" /v "%%~I" /f REM add more here ...


Only top voted, non community-wiki answers of a minimum length are eligible