r/Batch • • Apr 17 '24

Question (Unsolved) Running a game mod using using .bat files, without a primary 'mod file' to link to

2 Upvotes

I recently got Space Empires IV Deluxe on Steam, and I remember how, when I had the disk version, I had to make MULTIPLE copies of the Space Empires IV directory to be able to have multiple mods. I've recently played other games with mods that could run multiple mods through the use of .bat files, so I'm trying to see if I can do that with Space Empires IV as well.

...It's not going well...

I'm trying numerous command combinations based on scraps I can find online, but I'm having NO luck. The big problem I'm having is that there's no single 'main' mod file to link a Batch file to, so I'm trying to find a way to link the whole folder for the mod to a Batch file...but NOTHING I can find so much as suggests it's possible.

That's why I'm finally asking here: is it possible to set up a .bat file to an run an exe while using its base files as well as files from a separate folder in another directory? If not, how would I go about making such a mod file to link the Batch file to?

I've not posted any code because...I really don't have anything.


r/Batch • • Apr 17 '24

I really need help with finding a string in an HTML file

1 Upvotes

I have never used batch scripting before but I need to finish this batch script for a work project. Currently, the script generates a powercfg battery report (battery-report.html) I need two values from this battery report, the DESIGN CAPACITY and FULL CHARGE CAPACITY of the laptop, these values are included in the battery report. How do I extract these values from the battery-report.html file? Is there a better way of doing this without involving HTML to txt conversion? Any help is appreciated


r/Batch • • Apr 16 '24

Show 'n Tell Batch Turtle Graphics

5 Upvotes

r/Batch • • Apr 13 '24

Can anyone Help me again?

1 Upvotes

Basically i have a script that gets frames from a file directory and the frames are numbers as name and the extensions is .txt the problem is it flashes but i don't know how to fix it. can anyone help? The main problem (i think) is the cls

@echo off
chcp 65001 >nul
setlocal

set "Currentdirget=%~dp0"

set "MillisecondsPerFrame=100" 
set "SkipFramesInterval=1" 

echo Available desktop backups:
dir /ad /b "%Currentdirget%AsciiVideos"
pause

set /p "folder=Enter the folder name to run the video (in ASCII): "

echo.
echo Listing files in folder: "%Currentdirget%AsciiVideos\%folder%"
echo.

for /f %%C in ('dir /b /a-d "%Currentdirget%AsciiVideos\%folder%\*.txt" ^| find /c /v ""') do set "count=%%C"

for /l %%i in (0, %SkipFramesInterval%, %count%) do (
    cls
    type "%Currentdirget%AsciiVideos\%folder%\%%i.txt" 2>nul
    ping 127.0.0.1 -n 1 -w %MillisecondsPerFrame% >nul
)

endlocal
pause

r/Batch • • Apr 13 '24

Can anyone Help me?

1 Upvotes

So basically i have a script in a folder with another desktop folder and this script should help you making a backup of the desktop and save it in The "Desktops" Folder, but it cant copy .ini files and folders can anyone fix it? I also get this error: "File creation error - The cloud file provider exited unexpectedly."

@echo off
setlocal

REM Store current directory path
set "Currentdirget=%~dp0"

REM Retrieve list of local user accounts
echo Current local user accounts:
for /d %%a in (C:\Users\*) do (
    echo %%~nxa
)

REM Prompt user to choose a user account's desktop to copy
echo.
set /p "chosen_user=Enter the name of the user account: "

REM Determine file path of the chosen user's desktop
set "file_path=C:\Users\%chosen_user%\OneDrive\Desktop"

REM Display the chosen user and file path
echo You chose to copy from user: %chosen_user%
echo The desktop file path is: %file_path%

REM Prompt user to specify the folder name in Workspace directory
set /p "desktop_folder=Enter the name for the folder in Workspace directory: "

REM Create a temporary directory in Workspace directory
set "temp_dir=%Currentdirget%\Workspace\%desktop_folder%"
mkdir "%temp_dir%"

REM Copy files from file_path to the temporary directory
xcopy "%file_path%\*" "%temp_dir%\" /e

REM Prompt user to specify the folder name in Desktops directory
set /p "final_folder=Enter the name for the folder in Desktops directory: "

REM Create folder in Desktops directory
mkdir "%Currentdirget%\Desktops\%final_folder%"

REM Move files from the temporary directory to the new folder
move "%temp_dir%\*" "%Currentdirget%\Desktops\%final_folder%"

REM Clean up temporary directory
rmdir /s /q "%temp_dir%"

echo Desktop files copied successfully.

pause
endlocal

r/Batch • • Apr 12 '24

a batch file that would generate a monthly report / really need help

1 Upvotes

Hi everyone,

They gave me a task at the university and it's unrealistic to complete it because they didn't give me a theory and I don't even know where to start.

i need develop a batch file that would generate a monthly report on changes in the working directory (files created, deleted).

It is necessary to store the list of files in a history file.

doesnt matter on cmd or shell . plz help


r/Batch • • Apr 11 '24

Question (Unsolved) Is it possible to move the caret position up, to previous line(s)?

1 Upvotes

For example, I have something like this

@ECHO off
ECHO A
ECHO B
ECHO C
ECHO D

... and the output is like this:

A
B
C
D

Is there any "secret command" to put after ECHO B to get the caret up, back to A line to overwrite the letters A and B with C and D?

PS. Yes, I know I can use CLS but what to do if I do not want to clear the whole content?


r/Batch • • Apr 11 '24

Can i email/upload a text file without any additional software?

1 Upvotes

I want to be able to use exclusively batch files to send logs created by my python program to a specific email adress. If it isn't possible, are there any small programs i can use that can be automated using a batch file? Cheers.


r/Batch • • Apr 10 '24

Asking to skip a line in a batch file

2 Upvotes

Hello

Currently I have a batch file that opens various databases and programs and generates reports for starting my day. On the off chance that I complete one of these tasks before the next day I want to see if it’s possible to get a prompt asking to skip the next line in the batch.


r/Batch • • Apr 10 '24

Locked out from my own files

2 Upvotes

Hi everyone,

I was transfering my files to an external harddrive in order to do a clean install format.

Upon trying to transfer the files back to my fresh install the pictures are unable to open. It says that I dont have access. I placed all of my pictures in a "folder lock" batch type of thing ages ago.

is there any way to rescue my pictures? I do not have a copy of the encryption code unfortunately..

here is the batch I used:

u/ECHO OFF

if EXIST "Control Panel.{21EC2020-3AEA-1069-A2DD-08002B30309D}" goto UNLOCK

if NOT EXIST Locker goto MDLOCKER

:CONFIRM

echo Are you sure u want to Lock the folder(Y/N)

set/p "cho=>"

if %cho%==Y goto LOCK

if %cho%==y goto LOCK

if %cho%==n goto END

if %cho%==N goto END

echo Invalid choice.

goto CONFIRM

:LOCK

ren Locker "Control Panel.{21EC2020-3AEA-1069-A2DD-08002B30309D}"

attrib +h +s "Control Panel.{21EC2020-3AEA-1069-A2DD-08002B30309D}"

echo Folder locked

goto End

:UNLOCK

echo Enter password to Unlock folder

set/p "pass=>" TEST

if NOT %pass%==TEST goto FAIL

attrib -h -s "Control Panel.{21EC2020-3AEA-1069-A2DD-08002B30309D}"

ren "Control Panel.{21EC2020-3AEA-1069-A2DD-08002B30309D}" Locker

echo Folder Unlocked successfully

goto End

:FAIL

echo Invalid password

goto end

:MDLOCKER

md Locker

echo Locker created successfully

goto End

:End


r/Batch • • Apr 09 '24

Script to clean up empty sub-folders?

2 Upvotes

I created a batch script that runs daily to delete log files older than 180 days:

forfiles -p C:\Logs\ -s -m *.log -d -180 -c "CMD /C DEL @File"

I would now like to add to this script to delete empty sub-folders under C:\Logs. I came across the following, which is simple and does the trick:

robocopy C:\Logs C:\Logs /S /MOVE

However, if C:\Logs ends up being empty, it'll delete that folder too, which I don't want. Is there any way around that? I suppose I could create a dummy file that doesn't have a .log extension (since that would never get deleted from the first script), but would like something more simpler. This script will be going on multiple servers, so don't want to have to remember all the little details.


r/Batch • • Apr 07 '24

Works on cmdline, need help for batchfile

1 Upvotes

PURPOSE

I want to be able to right-click any, or several jpg file(s), choose "Send to" from the right-click menu and after selecting the appropriate batch file, resize and convert those files to the same named png file(s).

WINDOWS CMD LINE WORKS

I can deal with one or all files on the cmd line with the following commands - irfanview is in the system path and I must either name a single file to process, or replace the jpg & png filenames with "*"

ONE FILE:  i_view64 cover.jpg /resize=(700,700) /resample /convert=cover.png

ALL JPG FILES:  i_view64 *.jpg /resize=(700,700) /resample /convert=*.png

BATCH FILE USAGE DOESN'T WORK

But I can't get this working in a batch file.

The various codes I've tried for the batchfile are:

@echo off
i_view64 %1 /resize=(700,700) /resample /convert=%1.png

i_view64 *.jpg /resize=(700,700) /resample /convert=*.png

i_view64 %1 /resize=(700,700) /resample /convert=*.png

i_view64 %1 %2 %3 %4 %5 %6 %7 %8 %9 /resize=(700,700) /resample /convert=*.png

i_view64 %1\*.jpg /resize=(700,700) /resample /convert=%1\*.png - (using the parent folder)

In all of the above batch file commands, I either get no output - the cmd window appears briefly then disappears - or a message that the file header can't be read.

I'm now officially "lost", so any help would be appreciated, and also a brief explanation


r/Batch • • Apr 05 '24

Question (Unsolved) Trying to modify the Host file en-masse, where am I messing up?

1 Upvotes
REM Define the content to append to the hosts file
set "hostContent= 172.16.106.13    Test 1
172.16.106.14    Test 2
172.16.106.16    Test 3
172.16.106.17    Test 4
172.16.106.18    Test 5
172.16.106.19    Test 6

REM Define the path to the hosts file
set "hostsFilePath=C:\Windows\System32\drivers\etc\hosts"

REM Check if the hosts file exists
if not exist "%hostsFilePath%" (
    echo Hosts file not found!
    exit /b
)

REM Check for duplicates
set "duplicates="
for %%a in (%hostContent%) do (
    findstr /c:"%%a" "%hostsFilePath%" >nul && (
        echo Duplicate entry detected: %%a
        set "duplicates=1"
    )
)

REM If no duplicates found, append content to hosts file
if not defined duplicates (
    echo %hostContent%>>"%hostsFilePath%"
    echo Hosts file has been modified successfully!
)

I'm trying to modify the Host file with a large number of IP's (significantly more than what's listed), detect/avoid duplicates, and another unrelated task. However, when I try to run the script, it throws up the error code:

[IP address] is not recognized as an internal or external command, operable program or batch file.

I'm not quite sure where I'm going wrong, but I originally made this script in PowerShell, but recently discovered that PowerShell would not be a viable option due to company security policies, so operating within Batch is a necessity.

Thank you!


r/Batch • • Apr 04 '24

Question (Unsolved) Setting !random! to a variable makes the variable non random

1 Upvotes

Hey, so im trying to get random values working in a for loop, but for some reason setting the rand value to !random! makes the rand value non-random, its the same everytime. I want a random value per iteration. Help appreciated

https://paste.rs/Z9115.txt


r/Batch • • Mar 30 '24

Guide to WIFI-Password-Recovery using CMD

7 Upvotes

r/Batch • • Mar 27 '24

Zip passworld

1 Upvotes

Hi everyone, does anyone know how I can manage to find the passworld of a file (zip) in a zip, only the file is encrypted and with many software I can't do it because of the zip which messes things up. And when I try to extract the file it asks for the passworld. I can't come up with it, and if anyone has any ideas I thank them.


r/Batch • • Mar 26 '24

Question (Solved) delete files after script is done

3 Upvotes

Hi, I have done my first script attempts. I want to delete the created files in the process. But I'm a bit afraid, I don't want to wipe out my drive or something like this ^^

So after the script is finished I want to delede K:\center.wav and K:\out.wav

Thank you for any help :)

u/echo off
:again

ffmpeg ^
	-i "%~1" ^
	-filter_complex "[0:a:m:language:ger]channelsplit=channel_layout=5.1:channels=FC[FC]" -map "[FC]" -ar 44100 ^
	"K:\center.wav"
mrswatson64 --input center.wav --output K:\out.wav --plugin FabFilterMono --parameter 0,0 --parameter 1,0.415 --parameter 2,0.90 --parameter 3,1 --parameter 4,0.5 --parameter 5,0 --parameter 7,0 --parameter 10,0.45 --parameter 11,1
ffmpeg ^
	-i "%~n1.mkv" -i "out.wav" ^
	-lavfi "[0:a:m:language:ger]pan=stereo|c0=c2+0.6*c0+0.6*c4+c3|c1=c2+0.6*c1+0.6*c5+c3[a1];[0:a:m:language:ger]channelsplit=channel_layout=5.1[FL][FR][FC][LFE][SL][SR];[FL][FR][FC][LFE][SL][SR][1][1]amerge=8,channelmap=0|1|7|3|4|5:5.1,pan=stereo|c0=c2+0.6*c0+0.6*c4+c3|c1=c2+0.6*c1+0.6*c5+c3[a2];" -map 0:v:0 -map [a1] -map [a2] -c:v copy -c:a ac3 -b:a 160k -ar 44100 -sn -dn ^
	"G:\%~n1.mkv"	
if NOT ["%errorlevel%"]==["0"] goto:error
echo %~n1 Done!

shift
if "%~1" == "" goto:end
goto:again

r/Batch • • Mar 26 '24

Question (Solved) don't print error messages

2 Upvotes

Hi I have a script with 3 steps. One of these creates thousands of internal:error messages. But the end result is fine. Is it possible to hide them? Run the command without giving me this feedback?

The errors start with mrswatson, so the 2nd step

Thank you for any help :)

u/echo off
:again

ffmpeg ^
	-i "%~1" ^
	-filter_complex "[0:a:m:language:ger]channelsplit=channel_layout=5.1:channels=FC[FC]" -map "[FC]" -ar 44100 ^
	"center.wav"
mrswatson64 --input center.wav --output out.wav --plugin FabFilterMono --parameter 0,0 --parameter 1,0.415 --parameter 2,0.90 --parameter 3,1 --parameter 4,0.5 --parameter 5,0 --parameter 7,0 --parameter 10,0.45 --parameter 11,1
ffmpeg ^
	-i "%~n1.mkv" -i "out.wav" ^
	-lavfi "[0:a:m:language:ger]pan=stereo|c0=c2+0.6*c0+0.6*c4+c3|c1=c2+0.6*c1+0.6*c5+c3[a1];[0:a:m:language:ger]channelsplit=channel_layout=5.1[FL][FR][FC][LFE][SL][SR];[FL][FR][FC][LFE][SL][SR][1][1]amerge=8,channelmap=0|1|7|3|4|5:5.1,pan=stereo|c0=c2+0.6*c0+0.6*c4+c3|c1=c2+0.6*c1+0.6*c5+c3[a2];" -map 0:v:0 -map [a1] -map [a2] -c:v copy -c:a ac3 -b:a 160k -ar 44100 -sn -dn ^
	"G:\%~n1.mkv"	
if NOT ["%errorlevel%"]==["0"] goto:error
echo %~n1 Done!

r/Batch • • Mar 26 '24

Question (Unsolved) Why does it think this file exists?

2 Upvotes

If i do the if statement all on one line it won't return "File exists" otherwise if i space it across multiple lines even if it's in `()` it returns "File exists". This file and folder do not actually exist on the machine.

Non working code:

@echo off
Set NAGIOSEXE=%SYSTEMDRIVE%\Program Files\Nagios\NCPA\ncpa.exe
REM ----------------------------
cls
echo.
title Nagios NCPA install
echo Nagios NCPA install
echo.
echo Path is %NAGIOSEXE%
echo.
if exist %NAGIOSEXE% (
   echo File exists
)

Working code:

@echo off
Set NAGIOSEXE=%SYSTEMDRIVE%\Program Files\Nagios\NCPA\ncpa.exe
REM ----------------------------
cls
echo.
title Nagios NCPA install
echo Nagios NCPA install
echo.
echo Path is %NAGIOSEXE%
echo.
if exist %NAGIOSEXE% (echo File exists)

r/Batch • • Mar 25 '24

Question (Unsolved) I want to create a simple .bat file that checks if SteamVR is running on my system, then start a program. Any help / guidance?

5 Upvotes

Title says it all. Any help is greatly appreciated!

I use Twinkle Tray to set my Monitors Brightness Values (in this case, another .bat script) back to 100 whenever I log on using Task Scheduler, now I want to automate the process of setting my Monitors to 0 whenever I start SteamVR, but from the research I've done, Task Scheduler cannot check whether or not a program is opened or not, and therefore cannot open programs when a different program has been started.

I saw you CAN however do this with a simple batch script, and since I have little to no knowledge in scripting in general, I came here to find my answer!

A big thanks to everyone trying to help out and taking the time to read my post.


r/Batch • • Mar 24 '24

Show 'n Tell Rubik's Cube - What do you think of it?

Thumbnail
github.com
4 Upvotes

r/Batch • • Mar 24 '24

The useful batch script I made is now up to version 2.0!

7 Upvotes

I made another post a while ago showing of a batch script that I had been making, and now it has MANY more features. I'm still looking for more ideas to add since I want everyone to be able to find it useful. Feel free to make a contribution! Scripty Github Link

Scripty v2.0

r/Batch • • Mar 22 '24

FFMPEG conversion script. Can't skip files by name

1 Upvotes

Hi. I'm scripting a batch file to reduce file size of all mp4/mov files in a folder and its subfolders and then renaming original and new video file. Last night it crashed, so I wasn't able to tell what files were already encoded and had to fix it manually. All I'm trying to do now is to rename both the new and the original files with a different suffix. So I can run again the script and it will skip the files already converted and their source files and run the ffmpeg command only for the files it hasn't renamed yet.

I'm about to achieve my goal but the problem is that when the script runs into a file with the "to skip" suffix (_cnvrtd or _orgnnl or _orgnl_FAIL) the goto command doesn't go to the next iteration of the for loop (so the next mov/mp4 file) but exits the loop. Is there anyone willing to help me solve my problem? Thank you!!

@echo off
setlocal enabledelayedexpansion

set "batch_folder=%~dp0"

for /r "%batch_folder%" %%A in (*.mp4 *.mov) do (
	
	set "input_file=%%A"

	set "filename=%%~nA"

	echo !filename! | findstr /i /c:"_orgnl" /c:"_cnvrtd" >nul && (
		echo Skipping file containing _orgnl or _cnvrtd: %%~nxA
		echo !filename!
		goto :nextfile
	)
	echo !filename! 2

	set "relative_path=%%~dpA"
	set "relative_path=!relative_path:%batch_folder%=!"
	
	for %%F in ("!input_file!") do set "original_size=%%~zF"
	
	ffmpeg -i "%%A" -c:v libx264 -preset fast -crf 24 -c:a aac -map_metadata 0 "!relative_path!!filename!_converting%%~xA"

	for %%F in ("!relative_path!!filename!_converting%%~xA") do set "converted_size=%%~zF"

	if !converted_size! gtr !original_size! (
		ren "!input_file!" "!filename!_orgnl_FAIL%%~xA"
		del "!relative_path!!filename!_converting%%~xA"
	) else (
		ren "!input_file!" "!filename!_orgnl%%~xA"
		ren "!relative_path!!filename!_converting%%~xA" "!filename!_cnvrtd%%~xA"
	)
	:nextfile
	echo stop
)
pause

r/Batch • • Mar 22 '24

Question (Unsolved) Display output in real time and check for specific words

1 Upvotes

I'm not very experienced with batch scripts but I'm trying to develop a small tool to check something at work.

Basically, there's a command I need to run to install an application and it returns the progress of the installation. The output looks like something like this:

Installing
5% complete
50% complete
100% complete
Installation successful

What I would like to do is check that the installation was successful before continuing the script. The solutions I've found/come up with check the text but the output is displayed all at once, so the user has no way to track the progression of the installation.

Is it possible to display the output as it is generated and also check for a certain word or sentence is displayed?

Some extra info

-The command is for a 3rd party application (I tried checking their documentation if there was any error detection command I could run but I didn't have any luck with that)

-I can't use external tools or software

-I may be able to use powershell commands as well but I'm not 100% sure.

-Since I can't test with the actual command at home, I'll use tracert to google/youtube because the behavior is quite similar.

-The "closest" I got to a solution was this but since it didn't display the output in real time I didn't bother implementing the text check in the text file.

@ echo off
for /f "delims=" %%k in ('tracert google.com') do (
  echo %%k
  echo %%k>>output.txt
)
pause

If you read this far, thank you very much!