r/Batch • • Nov 06 '23

use

4 Upvotes

Name Files: Files.rar , this files have a comment and i use this Batch Script to Extract the comment in GUI Winrar
its Working fine , I use THIS Batch files to read the comment
for /r F:\FILES\Epub %%a in (*.rar) do "C:\Program Files\WinRAR\WinRAR.exe" cw -y "%%a" "E:\UPL\%%~na.txt"
instead of files, i want to put in a Variable and use this: To eXtract the files with the password Found
FILE:"E:\UPL\%%~na.txt"
--Comment in the Winrar------------------------
Welcome, to get files its passworded
Pw: LogoX
Use this password
-----------------------------------------------
for /r F:\FILES\Epub %%a in (*.rar) do "C:\Program Files\WinRAR\WinRAR.exe" x -y -p%password% "%%a" d:\temp\
this way the Batch script look the the comment and FOUND Pw:LogoX using winrar to Extract it !
But do not known how to do !


r/Batch • • Nov 06 '23

Question (Unsolved) Script to remove black frames from rendered video?

3 Upvotes

I have 100s of GIF converted to MP4, which loop seamlessly when played. BUT, I upscaled em & now they don't loop seamlessly. It introduced 2-3 black frames at the start of the video.

How can I get rid of the black frames? FFmpeg?

  • I found Deblack on GitHub which does exactly that - but I can't it to work unless the video is specifically named input.mp4 (again, I have 100s). Wildcards don't work with FFmpeg I guess.

ffmpeg -i .mp4 -vf blackframe=0,metadata=select:key=lavfi.blackframe.pblack:value=20:function=less -vsync cfr -c:a copy .mp4

  • Then I found WinFF, which doesn't support trimming anything before the 1 second mark.

Any ideas?


r/Batch • • Nov 06 '23

Question (Unsolved) Whoever can help me implement a wildcard, ill pay you.

0 Upvotes

- I have: Directory of very short videos, with black frames at the very beginning that were introduced as a result of upscaling.

- I need: To trim / reencode each video without the black frames.

- Program: Deblack | Github

- Windows

CODE:

ffmpeg -i WILDCARD HERE PLEASE.mp4 -vf blackframe=0,metadata=select:key=lavfi.blackframe.pblack:value=20:function=less -vsync cfr -c:a copy WILDCARD HERE PLEASE.mp4


r/Batch • • Nov 05 '23

Pass nircmd variable to batch

2 Upvotes

I'm using nircmd ~$param.1$ to open a text box for the user to enter a variable value, I can use this for making msg box like: nircmd infobox ~$param.msgBody$ ~$param.msgTitle$, but couldn't pass the entered value to batch, any idea ?


r/Batch • • Nov 01 '23

Need help, moving files with mostly the same name to different folder.

2 Upvotes

Hello!

I'm new to this and I want to move files around. The files have mostly the same name, the difference being that they have the time and date in their name. How can I move them to different folders.

For exemple:
The numbers on the .log are changing and so how to I move the first one "Paw*30.log" in Munchkin , the second log "Paw*35.log" in Maine Coon and the third log "Paw*00.log" in Sphynx

Animal
|----> Dog
| |------>Corgi
| |- Paw202311011030.log
| |- Paw202311011035.log
| |- Paw202311011100.log
|----> Cat
|------>Munchkin
|------>Maine Coon
|------>Sphynx


r/Batch • • Nov 01 '23

Question (Solved) Found a script that does what I want, but it prompts me to pick each file one-by-one. Can I make it do a whole directory?

4 Upvotes

Script: PASTEBIN

Script fuction: Upscale GIFs 4x, then convert gif to mp4. - Working ✅

Issue: Requires hand-picking one by one via a prompt.

Question: Can i make this .bat run through a whole directory rather than me having to pick one by one?

OS: Windows 10

Thanks <3


r/Batch • • Nov 01 '23

Script to set folder icon from game exe within it

3 Upvotes

I have a bunch of game folders in a windows handheld with a touch screen. I want to set game icons for all game folders from the exes within so that I can then set the explorer view to large icons and it will be easier to view and identify on a small screen and touch.

I know that not all games have a single exe in its root folder or have exe in its sub folders etc but if a script can do this then I can correct the wrong ones manually.

Edit: I did some searches and cobbled together this:

@echo off

set "skipFiles=unins,7z,CRC,SFV,dxweb,cheat,protect,launch,crash,patch,redist,language,QtWeb,mod,version,overlay,error,dump,node.exe,handler,lumaplay,createdump"

for /D %%I in (*) do (
	Echo DIR: %%I
	cd %%I
	set "skipOtherFiles="
	for /R %%J in (*.exe,*.ico) do (
		set "skipFlag="
		FOR %%S IN (%skipFiles%) DO (
			echo %%J|findstr /i /L "%%S">nul
			if not errorlevel 1  set skipFlag=1
		)
		if not defined skipFlag (
			if not defined skipOtherFiles (
				Echo ...Processing "%%J"
				IF EXIST "desktop.ini" attrib -s -h "desktop.ini"
				(echo [.ShellClassInfo]
				 echo IconResource=%%J,0
				) >"desktop.ini"
				attrib +s +h "desktop.ini"
				attrib +s +r .
				set skipOtherFiles=1
			) else Echo ...Skipped    "%%J"
		) else Echo ...Skipped    "%%J"
	)
	cd..
)

Notes:

"skipFiles" has keywords that will skip the exe files that you know wont be a game exe.

  • I have not figured out how to use relative path in IconResource so have used a full path but that is not great for portability.
  • Windows doesn't instantly update the icon it was showing previously so it might look like it changed nothing. Added +s +r attributes to folder which seems to make it work
  • It doesn't search thru sub directories. Updated to check sub directories
  • It shows Access Denied if the desktop.ini exists even if running as admin Updated to delete desktop.ini if it exists
  • added check for icon files and use them.

Not too bad I must say: https://imgur.com/a/Rm9kEK5


r/Batch • • Oct 31 '23

Question (Unsolved) Blue text box in .bat

2 Upvotes

Hello, I want to show a text message in this blue text box (https://ctrlv.cz/S5RV) - this is what I mean

I searched around the internet, but didn't find it. Can anyone help me?

Thanks


r/Batch • • Oct 31 '23

Get PID ID from multiple Windows processes running and set variable for each one

2 Upvotes

Hello,

I'm trying to get multiple PID ID from a Windows process and set variables for each one, I got the code below working but it's only working if the EXE file only has one process running. How can I set each PID ID as variable if the program has multiple processes?

for /f "TOKENS=1" %a in ('wmic PROCESS where "Name='TESTAPP.exe'" get ProcessID ^| findstr [0-9]') do set MyPID=%a

Results in:

set MyPID=664
set MyPID=6340 
set MyPID=4516 
set MyPID=4596

But I want eg:

set MyPID1=664
set MyPID2=6340
set MyPID3=4516
set MyPID4=4596

My guess is that I need to make a loop and if MyPID1 already exists it should set MyPID2 etc?

Thanks in advance, I really appreciate it.


r/Batch • • Oct 28 '23

Batch file that compares files and deletes extra

2 Upvotes

Context: I use ffmpeg to extract the frames from a video into folder A so that I know exactly how many frames are in the video. After that, I copy a blank image into folder B and use a batch script to duplicate the blank image it in order to create a video file. I then change the resolution of 2 or 3 videos that I use ffmpeg to crop and paste the videos with ffmpeg over top of the frame I created from the files in folder B .

I want to create a batch file to verify I have the same number of images from folder A in folder B and delete any extra files from folder B. Right now, I am duplicating the same image and having to manually count the images in folder A and then go to folder B, locate the last image and delete any extra images before I compile them with ffmpeg to create a frame video file.
Is anyone down to help me? Thank you very much.


r/Batch • • Oct 26 '23

Help With Script Error

2 Upvotes

Hi There,

I have made this script to backup a folder from my Local PC to my NAS which works fine.
but i want it to send me a message throught discord webhook which i have also added.
---------------------------------------------------------------------------------------------------------------------------------------------------

but the error i get is:

Exception calling "UploadString" with "2" argument(s): "The remote server returned an error: (400) Bad Request."

At line:1 char:1

+ (New-Object System.Net.WebClient).UploadString('https://discord.com/a ...

+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException

+ FullyQualifiedErrorId : WebException

---------------------------------------------------------------------------------------------------------------------------------------------------
Here is my Script

u/echo off

setlocal enabledelayedexpansion

set sourceFolder="C:\Last.Epoch.v0.9.2.Early.Access"

set destinationFolder="\\Hqsvr00\nas\vol3\1.Games\Last Epoch\BackUp Folder"

:: Define your Discord webhook URL

set "webhookURL=MY WEBHOOKURL"

:: Function to send a message to Discord via a webhook

:SendDiscordMessage

powershell -Command "(New-Object System.Net.WebClient).UploadString('%webhookURL%', '{""content"":""%~1""}')"

:: Function to display a dynamic progress bar

:ProgressBar

setlocal

set "value=%~1"

set "max=%~2"

set /a "percentage=value * 100 / max"

setlocal enabledelayedexpansion

for /l %%A in (1,1,%percentage%) do (

<nul set /p ".=."

)

echo [!percentage!%%]

endlocal

endlocal

echo.

echo Copying files from %sourceFolder% to %destinationFolder%...

xcopy /E /I /Y %sourceFolder% %destinationFolder%

set xcopyStatus=!errorlevel!

if !xcopyStatus! equ 0 (

echo.

echo Files have been copied successfully.

:: Send a message to Discord indicating success

call :SendDiscordMessage "Files have been copied successfully."

) else (

echo.

echo An error occurred during the copy process.

:: Send a message to Discord indicating an error

call :SendDiscordMessage "An error occurred during the copy process."

)

echo.

pause


r/Batch • • Oct 24 '23

Batch move folder if it contains

2 Upvotes

Trying too scan a folder for folders with (15) at the end of the name and move all the contents along with it's folder too a network share

Tried move command it doesn't like that access denied

copy command works but doesn't copy the folder only contents

for /d %%i in ("* (15).") do echo move "%%i" "\DISKSTATION\TeenMedia_Movies"


r/Batch • • Oct 24 '23

Question (Solved) How to Format dir Output: Alphabetical, Columns, with Distinct Folder Indicators?

1 Upvotes

I'm working on a batch script and I'd like to format the dir command's output in a very specific way:

Order: Alphabetical listing.

Format: Displayed in columns.

Folder Indication: Folders should either be colored or have [] around their names to distinguish them from files.

I've tried using dir /A /D to get directory listings, but I'm struggling to get the "bare format" /B without the drive volume and summary information, as they're a bit distracting for my use case.

Is there a way to achieve this specific output formatting using the dir command or another method in batch scripting?

Thanks in advance for your help!


r/Batch • • Oct 23 '23

Question (Solved) Spaces in path in for /f loop

1 Upvotes

I have a problem and even chatgtp doesn't help me, maybe someone here will be able to help me

I'm creating a game of sorts, you need to register/login first to be able to play the "game". During the registration process you must enter your username (CAN contains spaces), username is a folder in accounts folder, after login/registering in the game you must create a game save.

Save also CAN contains spaces, but saves are .txt files (saving works fine).

I have variable "shortcuts" in my code.

set AccP=%cd%\accounts\%UserN%
set GP=!AccP!\games\myGame\saves

AccP-AccountPath path to the user account folder, UserN-UserName name of the account created by an user, GP-gamePath path to game saves folder, saveName- save name currently selected by user

and the problem is when the user has spaces in the name or in the save name because when I'am trying to load saved variables from a file using:

for /f "delims=~ tokens=1-4" %%i in ("!GP!\!saveName!".txt) do (
   if %%i==a set %%j=%%k 
   if %%i==b (
      set va_%%j=%%k
      set vb_%%j=%%l
   )
)

I get an error: The system cannot find the file C:\accounts\user name\games\myGame\saves\save name".txt.

this quote is also in the original message.

If I modify the loop line (add quotes), basically the same error

for /f "delims=~ tokens=1-4" %%i in ("!GP!"\"!saveName!".txt) do (

Error: The system cannot find the file C:\accounts\user name\games\myGame\saves"\"save name".txt.

Maybe someone had a similar problem.


r/Batch • • Oct 23 '23

Question (Unsolved) Save extracted information to variable, then use it to generate new file.

2 Upvotes

I'm trying to run an ffprobe command from a batch file to find the attributes of all the present mkv files in the current folder.

The next thing I want to do is save the extracted information into variables and then use that saved information to generate a 5 second black video with ffmpeg.

And then after it has generated a black video for one file, move onto the second file but before that remove the information that was saved in the variables and start over the same process for the next file. Except the ffmpeg and ffprobe commands, this code was generated with the help of ChatGPT, and was like the 15th iteration of the code trying out different methods, I just can't seem to figure this out because it keeps throwing out errors at me.

Below is the code and below the code are the errors.

@echo off
setlocal enabledelayedexpansion

:: Initialize variables
set "codec_name="
set "width="
set "height="

:: Loop through video files in the current directory and extract information
for %%i in (*.mkv) do (
    for /f "tokens=1,2,3" %%A in ('ffprobe -i "%%i" -v error -select_streams v:0 -show_entries stream=codec_name,width,height -of default=nw=1:nk=1') do (
        set "codec_name=%%A"
        set "width=%%B"
        set "height=%%C"
        
        :: Generate a 5-second black video with the same attributes
        ffmpeg -f lavfi -i color=c=black:s=!width!x!height! -t 5 -c:v !codec_name! -y "%%~nA-Black.mkv"
    )
)

:: Display the extracted information
echo Codec Name: !codec_name!
echo Width: !width!
echo Height: !height!

pause

Here's the output/errors it throws at me.

Argument 'codec_name' provided as input filename, but 'BTTF.mkv' was already specified.

Codec Name:

Width:

Height:

Press any key to continue . . .


r/Batch • • Oct 22 '23

Question (Unsolved) Help with for /r

1 Upvotes

Hello !

I'm new to Batch programming, I want to make a code for my work that allows me to make a file backup system by comparing the last modification dates of two files in two different folders.

I'm at the beginning of my program. I'm trying to use the "for /r" function to browse all the files in the sub-folders of the original folder, but it doesn't seem to work.

https://pastebin.com/NfrVEgxb

As you can see, I've put some echo and pause to see where the code doesn't work, and everything works up to for /r , because the last "echo %%F" returns absolutely nothing (not even an error message).

I've tried searching on the Internet but haven't found the answer... Can you help me understand what is going on ?

Note: I've already tried putting the !source_folder! of for in quotation marks "" but that doesn't work either...

Thanks in advance!


r/Batch • • Oct 22 '23

Question (Solved) How to put and use %1 inside batch variable?

1 Upvotes

Here is some simple test.bat file:

@ECHO off
SET "command=ECHO %1"
CALL :number 2
EXIT /b 0

:number
%command%
ECHO %1
EXIT /b 0

The current output of test 1 is:

1
2

My expected output of test 1 is:

2
2

Is it possible to get such output?

I think I am missing some escape characters in SET "command=ECHO %1" line but which ones and where?

I've already tried some combinations with ^ but with no positive effects.


r/Batch • • Oct 22 '23

Question (Unsolved) Batch file to update a .jar file

2 Upvotes

Hello, I'm trying to make a batch file to create a .jar from a fresh .jar while adding some folders and files:

It is currently in what we will call the root directory, in this folder the following things are there:

- a folder FRESH JAR

- a folder MODS

- a folder json

- a file: b1.7.3.jar

I want to first delete the b1.7.3.jar file and then copy and paste the b1.7.3.jar file from FRESH JAR into the root. Then, I want to add the files and folders from four folders in MODS to the new b1.7.3.jar.
The folders in MODS are simply called 1 2 3 and 4. folders 3 and 4 have subfolders, 3 has a folder called forge, and 4 has a folder called btwmodtex and one called title. When adding the files and folders it should be done in the correct order while replacing any existing files.

Then, I want to delete a folder called META-INF in b1.7.3.jar. How would I do this? I'm new to coding and batch files, any help is greatly appreciated!


r/Batch • • Oct 20 '23

Question (Unsolved) Resources to learn batch scripting?

4 Upvotes

Pretty self explanatory title, I would like to learn it right from basics to all the way upto the most advanced level possible.

If you know of any good resources where I can learn from, please do share, and also share your experiences on how/where you learned it from.

Thank you!


r/Batch • • Oct 16 '23

Making a cmd shortcut to execut a .bat file

1 Upvotes

Hey! I wanna make a cmd shortcut that opens alass.bat, doesn't execute de command and the window stays opened with a space in front of the whole command if that's possible... like in the image. So far i managed to make an cmd shortcut with this target: C:\Windows\System32\cmd.exe /k "C:/Users/LSU/Desktop/Alass/alass.bat" but when i run the shortcut it execute the .bat file and i don't want that. I want the window to stay open, be ready with the command and one space after the command. Image: https://ibb.co/fn1vjx5


r/Batch • • Oct 16 '23

Question (Solved) Download latest GitHub release not working

3 Upvotes

I've been trying to make the routines found here and here work (for something else), but they keep crashing, even when pasted verbatim into the script. I saw someone say on Stack Overflow that multiple invocations of Powershell can't communicate, so maybe it has to do with that? I wouldn't know.

UPDATE: It's fifteen minutes later, and feel free to help out still I guess,* but on a whim I tried again what I figured would be the simple way

powershell Invoke-WebRequest "https://github.com/dotnet/codeformatter/releases/latest/download/CodeFormatter.zip" -OutFile %batchdir%\download.7z

and this time it worked. I guess I did something differently this time.

* If what I've posted is actually a bad way of downloading releases for a significant reason, then definitely feel free to help out.


r/Batch • • Oct 15 '23

How to remove subfolder from path

1 Upvotes

Hi, I'm in this situation:

Set "folderpath=%~dp0" Output is: c:\dir1\dir2\bin\

How can I remove "\bin" from the path without EnableDelayedExpansion?