/r/Batch
r/Batch is all about the Batch scripting language, which runs in the windows CMD language. It can be used within the CMD, or via .bat files.
Batch programming is the windows CMD language. It can be used within the CMD, or via .bat files.
Resources
Windows Commands - 8.1/2008 and later
Batch Tutorials - YouTube Playlist
RULES
/r/Batch
i am following a tutorial about the nicla vision and it's telling me to Execute the specific batch code for your OS for uploading the binary (arduino-nicla-vision.bin
) to your board. how do i do it? i dont know anything about batch its my first time doing something like this.
if it helps this is the link for the tutorial: https://www.hackster.io/mjrobot/tinyml-made-easy-object-detection-with-nicla-vision-407ddd
I need a batch file that will remove the last of multiple underscores in a file name in the whole directory.
So basically I want a batch file that will rename the following:
2474_18531_1001_01.txt
2474_18531_1001_02.txt
2474_18531_1001_03.txt
2474_18531_1001_04.txt
To:
2474_18531_100101.txt
2474_18531_100102.txt
2474_18531_100103.txt
2474_18531_100104.txt
Thanks in advance!
I want to move subfolder to base folder only when there is single subfolder. Need only to look for 1st subfolder level.
For eg.
Folders from below:
D:\Music\AlbumABC\AlbumABC\CD1\track01.WAV
D:\Music\AlbumABC\AlbumABC\CD1\track02.WAV
D:\Music\AlbumABC\AlbumABC\CD2\track01.WAV
D:\Music\AlbumDEF\CD1\track01.WAV
D:\Music\AlbumDEF\CD2\track01.WAV
D:\Music\AlbumDEF\CD2\track02.WAV
D:\Music\AlbumDEF\CD2\track03.WAV
To this output:
D:\Music\AlbumABC\CD1\track01.WAV
D:\Music\AlbumABC\CD1\track02.WAV
D:\Music\AlbumABC\CD2\track01.WAV
D:\Music\AlbumDEF\CD1\track01.WAV
D:\Music\AlbumDEF\CD2\track01.WAV
D:\Music\AlbumDEF\CD2\track02.WAV
D:\Music\AlbumDEF\CD2\track03.WAV
Server.bat will be hosting the Batch Awards event once again. You can nominate your favorite batch projects from this year until 14th of December and then there will be a final vote for the best projects of this year on the server.bat discord server. You can nominate as many projects as you want but in the final vote you can vote for 3 nominees at max.
Special thanks to: einst1969, Icarus and Shivter for designing the banner for this year's Batch Awards!
Nominees are collected through Google forms:
https://forms.gle/ang94wWXX7kNASQL7
Hello all, I have this script that works perfectly well for the most part, it takes all the JPG files inside the current folder, reads the first 20 characters of the file name, makes a folder with that name, then moves each file into the corresponding folder.
So as I said it works just fine, but in the end, once the script is closed (when its done it doesn't make it its literally when the script finishes and closes after the last pause when done)
it creates a folder called: "~,20!-(CR)"in the folder where the script is run, this has probably something to do with the value of the variable "SET "FNX=!FNX:~,20!-(CR)" but not sure why it does it when it closes.
@ECHO OFF
ECHO.
ECHO !!!!!WARNING!!!!! DESTRUCTIVE OPERATION, CANNOT BE UNDONE!!!
ECHO.
ECHO This file will create Individual folders inside the current folder using the following Parameters and
ECHO sort all *.JPG* files in current directory accordingly
REM To change target or source directory simply type it in the variable field
SET "SRC=%~dp0"
SET "SRC=%SRC:~0,-1%"
SET "SRC=%SRC%\(Merged)\"
SET "DST=%~dp0"
SET "DST=%DST:~0,-1%"
ECHO.
REM For Diagnostics & Troubleshooting Purposes
ECHO Source: %SRC%
ECHO Destination: %DST%
ECHO Characters to use from the start of filename: 20
ECHO Where: %SystemRoot%\System32\where.exe "%SRC%":*.JPG*
ECHO.
ECHO To Cancel this operation press CTRL-C
PAUSE
SetLocal EnableDelayedExpansion
If Not Exist "%SRC%\" (Exit/B) Else If Not Exist "%DST%\" Exit/B
For /F "Delims=" %%A In ('%SystemRoot%\System32\where.exe "%SRC%":*.JPG*') Do (
CALL :SortnMove "%%A"
)
ECHO ************************ DONE ************************
PAUSE
:SortnMove
REMECHO ************************ BEGIN LOOP ************************
SET "FNX=%~nx1"
REM Replace 20 for the number of characters from the start of the filename you wish to use as Base for folder creation
SET "FNX=!FNX:~,20!-(CR)"
If Not Exist "!DST!\!FNX!\" (MD "!DST!\!FNX!" 2>NUL
If ErrorLevel 1 ECHO Unable to create directory !DST!\!FNX!)
ECHO Moving "%1" to "!DST!\!FNX!"
If Exist "!DST!\!FNX!\" (MOVE /Y "%1" "!DST!\!FNX!\"
If ErrorLevel 1 ECHO Unable to move "%1" to !DST!\!FNX!\)
REMECHO ************************ END LOOP ************************
goto:eof
Any help with this would be greatly appreciated
Hi all.
I have loads of video files that I need to make nfo for so Kodi can pick them up. I don't need any specs like frame rate or anything about the file itself, just the filename and number
so for example I have these files:
0x105 Steve Holiday.mkv
0x216 Linda Wales.mkv
I would like to generate a txt file that contains this, with just the <title> and <episode> fields different for each file
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?><episodedetails><title>Steve Holiday</title><showtitle>Holiday</showtitle>
<season>0</season>
<episode>105</episode>
<displayseason>1</displayseason>
<displayepisode>3</displayepisode>
<plot>Holiday.</plot>
<tagline></tagline>
<runtime></runtime>
<mpaa></mpaa>
<playcount>0</playcount>
<lastplayed></lastplayed>
<genre></genre>
</episodedetails>Any help is greatly appreciated
Hi everyone i need help i cannot work out a solution to my issue in my created batch file!!
Ive created a batch to convert an old unused ext4 block to swap and mount it as a zram partition for a specific set of android devices using recovery mode for an android system ive compiled.
It has around 600 lines of code, everything works as It should no issues there.
BUT when converting it to exe with bat to exe converter with embedded items I cannot add folders only files to be embedded.
I have it set to auto delete embedded files on exit, it dosent matter what stage of the batch script its currently at if console is closed then embedded files are deleted also.
Now the real issue im facing here with this is on start up of the batch script im creating a folder named RamPlus_Bin and am moving the embedded files to /RamPlus_Bin from / but doing this stops embedded files from being deleted on exit from main script.
What i want to do is be able to delete the files located in RamPlus_Bin folder then RD the folder itself automatically if the console is closed at any stage the same as if the embedded exe files were still at / where RamPlus.exe was run from but i want to do it from within the main batch file itself (RamPlus.exe) using batch code. Is this even possible ? I've spent the last 3 hours trying to figure out how to do it but cannot.
Any help would be greatly appreciated. 🙂
I want to create a script that moves a bunch of roms in the same directory to their corresponding folder depending of the first character, and if its a number, the folder is called "0-99".
The code works except for the names that contain "!" , any suggestion?
Thanks in advance
@echo off
chcp 65001 > nul
setlocal EnableDelayedExpansion
set "finalLog=final_files.txt"
:: Script para organizar archivos en carpetas y manejar números en la carpeta 0-99
echo Organizando archivos por su primer carácter...
:: Crear la carpeta 0-99 si no existe
if not exist "0-99" mkdir "0-99"
:: Crear carpetas para las letras A-Z si no existen
for %%l in (A B C D E F G H I J K L M N O P Q R S T U V W X Y Z) do (
if not exist %%l mkdir %%l
)
:: Contar el total de archivos a procesar
set "totalFiles=0"
for %%f in (*) do (
if not "%%~nxf"=="%~nx0" set /a totalFiles+=1
)
:: Variables para progreso
set "processedFiles=0"
:: Mover archivos al subdirectorio correspondiente
for %%f in (*) do (
if not "%%~nxf"=="%~nx0" (
:: Verificar que el archivo exista y no sea una carpeta
if exist "%%f" (
:: Obtener el primer carácter del nombre del archivo
set "fileName=%%~nxf"
set "firstChar=!fileName:~0,1!"
:: Verificar si el primer carácter es un número
if "!firstChar!" geq "0" if "!firstChar!" leq "9" (
:: Mover archivo a la carpeta 0-99
move "%%f" "0-99\" > nul
if errorlevel 1 (
echo Error al mover el archivo %%f a la carpeta 0-99
) else (
echo Archivo %%f movido a la carpeta 0-99
)
) else (
:: Mover archivo a la carpeta de la letra correspondiente
if exist "!firstChar!" (
move "%%f" "!firstChar!\" > nul
if errorlevel 1 (
echo Error al mover el archivo %%f a la carpeta !firstChar!
) else (
echo Archivo %%f movido a la carpeta !firstChar!
)
)
)
set /a processedFiles+=1
echo Progreso: !processedFiles! de !totalFiles! archivos procesados.
)
)
)
echo Proceso completado. !processedFiles! de !totalFiles! archivos procesados.
:: Listar los archivos restantes (ignorar carpetas y el script)
for %%f in (*) do (
if not "%%~nxf"=="%~nx0" if not "%%~dpf"=="\" if not "%%~xf"=="" (
echo %%f >> "%finalLog%"
)
)
pause
Hello all,
I have this batch file that for the most part works perfectly well, except that one of the variables inside the IF statements is not updating properly, no matter how much I set it with % or ! i just does not want to set itself
Must be something to do with delayed expansion and how im doing the % or the ! but i honestly can never understand the whole % or ! thing and I just try to copy syntax from other scripts that do work, in this case im dumbfounded and cant get it to work no matter what I try
Here's the script, what it does its not very important, what its supposed to do it does correctly, I can tell because if I put the value manually where the variable goes the script works just fine, so the issue is just why is the variable not updating, everything else should solve itself once that happens.
The problematic part has been specified on the script with an ECHO
Any help would be appreciated,
@ECHO OFF
ECHO.
ECHO !!!!!WARNING!!!!! DESTRUCTIVE OPERATION, CANNOT BE UNDONE!!!
ECHO.
ECHO This file will remove the last 3 characters from all files inside the current folder
ECHO.
SET "SRC=%~dp0"
SET "SRC=%SRC:~0,-1%"
SET "DST=%~dp0"
SET "DST=%DST:~0,-1%"
SET "EXT=*.JPG"
ECHO.
ECHO Source: %SRC%
ECHO Destination: %DST%
ECHO Type: %EXT%
ECHO Number of Characters Removed: -3
ECHO.
ECHO To Cancel this operation press CTRL-C
PAUSE
SETLOCAL EnableExtensions enabledelayedexpansion
ECHO This recurses through all folders, excluding any folders which match the exclusion words
for /F Delims^= %%F in ('Dir . /B/S/ON/AD^|%find.exe /I /V "WordsInFoldersYouWantToExclude"') do (
ECHO "%%F\%EXT%"
IF exist "%%F\%EXT%" (
sfor %%A in (%%F\%EXT%) do (
ECHO This Echoes A
ECHO %%A
ECHO This is the problematic part, it just will not update
SET "FNX=%%A"
ECHO This Echoes FNX
ECHO %FNX%
SET "FNX=!FNX:~0,-3!%%~xf"
ECHO THIs should echo filename FNX after mod
ECHO %FNX%%
echo %%~xA|findstr /v /x ".dll .bat .exe" && (
ECHO This next one echoes the file name minus 3
ECHO Renaming: %%A to: %FNX%
)
)
)
)
)
endlocal
ECHO ************************ DONE ************************
PAUSE
Hello, thankfully there's this place, since the StackOverflow guys are kinda 🍆
Ok so here's the gist of the problem, its a really weird one and i cant find a way to explain this or parse this, maybe someone else can think of a way
So essentially I have a software that opens up a file just like every other windows exe ever, if you put:
Softwarepath\software.exe c:\filepath\file.ext
The software will open the file as they always do, if I do this however:
Softwarepath\software.exe c:\filepath\file1.ext c:\filepath\file2.ext
It will open file 1 and 2 simultaneously, the software makers are not the nicest of people and do not want to add command line support, processing 16 thousand files one by one will be near impossible to do manually
So the question is.. can i do something like this:
for %f in (*.jpg) do call software.exe "%~f1" "%~f2" "%~f3" (and so on, 16 thousand times or as many files as it finds in the folder)
The problem is i cant just send each file one by one to the exe, i have to literally parse the whole list of files path and all and append it after the exe call command. i realize this will result in a gigantic huge command, but i do not know how else to do this, this is literally the only way the software allows any kind of automated input of files.
Essentially general idea is that the script will run, recurse through all folders, find all jpg files, then when its done building the "list" of files it found it will dump it as a gigantically large command to the software each file with full path after the software's .exe file.
The recurse folders bit can be done with this command:
FOR /R "C:\SomePath\" %%F IN (.) DO (
REM Gigantic command for each folder
)
but I cant figure out how to make the main command to call this to run.
Any help is appreciated.
Hey everyone! I am Schooi, I have been doing batch for some time and have gotten pretty good at it. I recently made a video (and a script) for making gradients using ESC codes (I showcase this with ASCII art)
YouTube video: https://www.youtube.com/watch?v=1ecuUu2UWW0
Please tell me your thoughs and otehr video ideas. Thanks
I figureed out how to do .bat extension!
So I recently found out about AhkToExe and it basically packages the .ahk
file into a .exe
. But what most interests me is that even when a big file is packaged, the size doesn't increase very much. Bat to Exe converters and IExpress usually makes few megabyte-sized EXEs for even small batch files. So I wonder if there's a way to put the batch file code into the AutoHotKey code and compile it with AhkToExe. I know about the Run
command in AHK but Batch script logic doesn't seem to work there, just single commands at a time. I want to know if there's a way to put the desired code into generate a temporary batch file when executed, and run that temporary batch file, all in AHK.
I'm quite new at batch scripting so idk most things
part of scripts:
@echo off
title Development - by ?
chcp 65001 >nul
color 5
cd files
:start
cls
call :banner
call :main_menu
:banner
echo.
echo.
echo ██████╗ ███████╗██╗ ██╗███████╗██╗ ██████╗ ██████╗ ███╗ ███╗███████╗███╗ ██╗████████╗
echo ██╔══██╗██╔════╝██║ ██║██╔════╝██║ ██╔═══██╗██╔══██╗████╗ ████║██╔════╝████╗ ██║╚══██╔══╝
echo ██║ ██║█████╗ ██║ ██║█████╗ ██║ ██║ ██║██████╔╝██╔████╔██║█████╗ ██╔██╗ ██║ ██║
echo ██║ ██║██╔══╝ ╚██╗ ██╔╝██╔══╝ ██║ ██║ ██║██╔═══╝ ██║╚██╔╝██║██╔══╝ ██║╚██╗██║ ██║
echo ██████╔╝███████╗ ╚████╔╝ ███████╗███████╗╚██████╔╝██║ ██║ ╚═╝ ██║███████╗██║ ╚████║ ██║
echo ╚═════╝ ╚══════╝ ╚═══╝ ╚══════╝╚══════╝ ╚═════╝ ╚═╝ ╚═╝ ╚═╝╚══════╝╚═╝ ╚═══╝ ╚═╝
echo.
echo.
goto :eof
:main_menu
for /f %%A in ('"prompt $H &echo on &for %%B in (1) do rem"') do set BS=%%A
echo.
echo.
echo ╔═(1) Apps
echo ║
echo ╠══(2) Websites
echo ║
echo ╚╦══(3) ?
echo ║
set /p input=.%BS% ╚═══^>
if /I %input% EQU 1 call :apps
if /I %input% EQU 2 call :websites
if /I %input% EQU 3 exit
cls
goto start
echo.
pause
:apps
for /f %%A in ('"prompt $H &echo on &for %%B in (1) do rem"') do set BS=%%A
echo.
echo.
echo ╔═(1) Bloxstrap
echo ║
echo ╠══(2) Discord
echo ║
echo ╠══(3) Roblox Player
echo ║
echo ╠══(4) Roblox Studio
echo ║
echo ╚╦══(5) Blender
echo ║
set /p input=.%BS% ╚═══^>
if /I %input% EQU 1 start Bloxstrap.lnk
if /I %input% EQU 2 start Discord.lnk
if /I %input% EQU 3 start Roblox.lnk
if /I %input% EQU 4 start Studio.lnk
if /I %input% EQU 5 start Blender.lnk
cls
goto start
echo.
pause
:websites
for /f %%A in ('"prompt $H &echo on &for %%B in (1) do rem"') do set BS=%%A
echo.
echo.
echo ╔═(1) Roblox Website
echo ║
echo ╚╦═(2) Youtube
echo ║
set /p input=.%BS% ╚═══^>
if /I %input% EQU 1 start /d "C:\Program Files (x86)\Microsoft\Edge\Application" msedge.exe www.roblox.com
if /I %input% EQU 2 start /d "C:\Program Files (x86)\Microsoft\Edge\Application" msedge.exe www.youtube.com
cls
goto start
echo.
pause
is making script like that possible? and if yes how, currently i know that i can set fixed wallpaper and disable option to change wallpaper on the computer, or on the current user via registry
I'm trying to have it where it asks for your username then when I type goto loop, it doesn't. What am I doing wrong?
Hi, I want to set the FPS value as a variable in my script. In this example it is line 27
| + Default duration: 00:00:00.040000000 (25.000 frames/fields per second for a video track)
Filename: "Value.A.txt"
+ EBML head
|+ EBML version: 1
|+ EBML read version: 1
|+ Maximum EBML ID length: 4
|+ Maximum EBML size length: 8
|+ Document type: matroska
|+ Document type version: 4
|+ Document type read version: 2
+ Segment: size 169552350
|+ Seek head (subentries will be skipped)
|+ EBML void: size 4027
|+ Segment information
| + Timestamp scale: 1000000
| + Multiplexing application: libebml v1.3.6 + libmatroska v1.4.9
| + Writing application: mkvmerge v29.0.0 ('Like It Or Not') 64-bit
| + Duration: 00:02:08.865000000
| + Date: Sun Oct 27 12:36:11 2024 UTC
| + Segment UID: 0x71 0xcf 0xe8 0xea 0x04 0x89 0x37 0x14 0x14 0xd0 0x28 0xbe 0xee 0x6d 0x34 0xef
|+ Tracks
| + Track
| + Track number: 1 (track ID for mkvmerge & mkvextract: 0)
| + Track UID: 1
| + Track type: video
| + Lacing flag: 0
| + Codec ID: V_MPEG4/ISO/AVC
| + Codec's private data: size 40 (h.264 profile: High @L4.1)
| + Default duration: 00:00:00.040000000 (25.000 frames/fields per second for a video track)
| + Video track
| + Pixel width: 1920
| + Pixel height: 960
| + Display width: 1920
| + Display height: 960
| + Video colour information
| + Horizontal chroma siting: 1
| + Vertical chroma siting: 2
| + Track
| + Track number: 2 (track ID for mkvmerge & mkvextract: 1)
| + Track UID: 2
| + Track type: audio
| + Codec ID: A_AC3
| + Default duration: 00:00:00.034829931 (28.711 frames/fields per second for a video track)
| + Language: ger
| + Audio track
| + Sampling frequency: 44100
| + Channels: 2
|+ EBML void: size 1107
|+ Cluster
Hi, I have a script that works but sometimes when it runs in the background and Im doing other things, the script can get stuck. The thing is that all my other scripts never stuck, so I wanted to ask if there is a flaw or something that could me improved?
Thanks for any help :)
edit: after replacing mpv with mkvinfo to get the "real" fps the script works without issues
This is the 1st script
@echo off
:again
set TARGET_DIR=%1
if "%~x1" equ ".mkv" set TARGET_DIR="%~dp1"
for /r %TARGET_DIR% %%a in (*.mkv) do call :process "%%a"
goto:eof
:process
ffprobe -v error -select_streams a:0 -of csv=p=0 -show_entries stream=channels %1 > channels.txt
set /p ACHANNELS=<channels.txt
if "%ACHANNELS%" gtr "3" (
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 K:\center.wav --output K:\out.wav --plugin BCPatchWorkVST,C:\VstPlugins\BlueCatClarity20Mono.fxp;FabFilterMono,C:\VstPlugins\FabFilterMonoPreset.fxp;C1compscMono,C:\VstPlugins\CompScMonoHarsh.fxp;C1compscMono,C:\VstPlugins\CompScMonoMud.fxp;FabFilterMB,C:\VstPlugins\MBpreset.fxp 2>nul
ffmpeg ^
-i "%~n1.mkv" -ss 51ms -i "K:\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 [a2] -map [a1] -c:v copy -c:a ac3 -b:a 160k -ar 44100 -sn -dn ^
"G:\%~n1.mkv"
del "K:\center.wav"
del "K:\out.wav"
del channels.txt
call "C:\VstPlugins\profiles\FPS.bat" "G:\%~n1.mkv"
) else (
ffmpeg ^
-i "%~1" ^
-map 0:a:m:language:ger -ar 44100 -vn -sn -dn ^
"K:\center.wav"
mrswatson64 --input K:\center.wav --output K:\out.wav --plugin BCPatchWorkVST,C:\VstPlugins\BlueCatClarity25.fxp;FabFilterDS,C:\VstPlugins\FabFilterDSPreset.fxp;C1compscStereo,C:\VstPlugins\CompScStereoHarsh.fxp;C1compscStereo,C:\VstPlugins\CompScStereoMud.fxp;FabFilterMB,C:\VstPlugins\MBpreset.fxp 2>nul
ffmpeg ^
-i "%~n1.mkv" -ss 51ms -i "K:\out.wav" ^
-map 0:v:0 -c:v copy -map 1:a:0 -map 0:a:m:language:ger -codec:a ac3 -b:a 160k -ar 44100 -sn -dn ^
"G:\%~n1.mkv"
del "K:\center.wav"
del "K:\out.wav"
del channels.txt
call "C:\VstPlugins\profiles\FPS.bat" "G:\%~n1.mkv"
)
goto:eof
This is the 2nd script that gets called "FPS"
@echo off
setlocal
set "inputFile=%~1"
mpv --no-config --vo=null --no-video --no-audio --no-sub --msg-level=cplayer=info %1 > Value.A.txt
mediainfo --Inform="Video;%FrameRate_Original%" %1 > Value.B.txt
rem Check Value.A.txt for "--vid=1" and retrieve the corresponding value in column %%g
for /f "tokens=1-10" %%a in (Value.A.txt) do (
if "%%g" equ "fps)" set "ValueA=%%f"
if "%%h" equ "fps)" set "ValueA=%%g"
if "%%i" equ "fps)" set "ValueA=%%h"
if "%%j" equ "fps)" set "ValueA=%%i"
)
rem Check Value.B.txt for "Original" and retrieve the corresponding value in column %%e
for /f "tokens=1,2,3,4,5" %%a in (Value.B.txt) do (
if "%%a" equ "Original" set "ValueB=%%e"
)
rem Set default RESULT to GOOD
set "RESULT=GOOD"
rem Check if both ValueA and ValueB are defined and if they do not match
if defined ValueA if defined ValueB if "%ValueA%" neq "%ValueB%" set "RESULT=BAD"
rem Run different ffmpeg commands based on the result
if "%RESULT%" equ "GOOD" (
echo %ValueA%
echo %ValueB%
) else (
mkvmerge -o "%~dpn1_merge.mkv" --default-duration 0:%ValueA%p --fix-bitstream-timing-information 0:1 "%inputFile%"
del "%inputFile%"
)
del Value.A.txt
del Value.B.txt
I have used Robocopy in the past. Perhaps it's still a current tool? I wasn't sure it could do what I need to now:
a) I have a directory tree with thousands of file in about 20 folders (each with perhaps a few subfolders) created over many years. Just personal data.
b) Not many files are added each month. But the files could be sprinkled around anywhere in the directory tree.
c) I'd like to copy to a new folder: any files that were created or altered this calendar year (e.g from 2024-01-01 until now). Not sure if it's the right term, but I think this is called a differential backup (as opposed to an incremental backup).
Question: Does someone have a batch file using Robocopy (or a reliable alternative) to do this?
My intention is to use Task Manager to run this every week so that I have a weekly full backup of whatever happened this year. This is to augment a full backup that I would have created on Dec 31 of the previous year.
A disaster recovery would be the restore a full backup of the directory tree plus the latest "weekly" differential.
A bonus would be to do daily pseudo incrementals based on any new files created or altered in the past week.
The goal is to do these weekly and daily backups because they will be very small because of the small number of files involved (they would be small compare to the much larger full backup that comprises all the files created over the past many years).
I would then compress and encrypt the differential tree into a single small file and upload it to the cloud daily.
I don't know how I would go about doing this. I understand that their is no registry key for this group policy. I tryed using process monitor to take note of what is changing when the policy is updated but it just runs a bunch of mcc.exe operations like regOpenKey RegCloseKey RegQueryKey and RegEnumKey
right now i'm making a set of folders based off a text file. The text file has a list of 24 names with a sequential number before it. (1 SMITH, 2 BARKER, 3 TURNER....) with each on it's own line. I'm using this to make the folders:
FOR /F "usebackq delims=" %G IN (_names.txt) DO md "%G"
But it would be easier for me to not have to put the number in the text file; if the text file ONLY has names (SMITH, BARKER, TURNER), could I generate the numbers in the command line at the same time that it's pulling from the text file? In other words, i want to do this:
FOR /L %N IN (1,1,24) AND FOR /F "usebackq delims=" %G IN (_names.txt) DO md "%N %G"
... but that's not correct syntax :)
Hi,
This is probably very basic, but I've done some googling & can't find the answer so figure this is a good place to ask.
I run some very basic python scripts on a computer that I use as a server, and these scripts are meant to start on boot (i.e the .bat files are in the startup folder.
This works fine, however when I run the .bat files normally, the python script runs within the CMD window as if I had run
> python ScriptName.py
However when it runs through the startup procedure it instead opens a seperate Python 3 window and then runs the code within this (I am unsure how one would normally do this, but you see my point).
Does anyone know the cause of this discrepancy? And if so how I would go about changing it? (from my side if my code is bad & the script dies running it in a CMD window holds the error message open, so that I can see what the issue was when I come around to seeing it).
For clarity my .bat scripts are as follows:
@echo off
cd "C:\Users\UserName\FolderName"
cmd /c "python ScriptName.py"
Hello, r/Batch. I'm relatively new to batch script, and I was wondering; would it be possible to have a batch script that searches for a specific string in a database, then returns all of the associated data?
Example:
I (theoretically) have a database, with, let's say, a bunch of details about the various filetypes in it. Would it be possible to make a batch script that I would ask to, say, look up ".wad" files, then the program would look through the data contained in the database and show the data about ".wad" files, provided it is in the database.
Thanks for any helpful reply.
Yes it's called FSIT (Friendly System Information Tool) With friendly i meant it isn't malware.
Save as .BAT (all files).
@echo off
title Friendly System Information Tool :)
color 0A
:mainMenu
cls
echo =====================================================
echo :) :) FRIENDLY SYSTEM INFORMATION TOOL :) :)
echo -----------------------------------------------------
echo What would you like to know? Type a keyword:
echo.
echo - CPU - RAM - DISK
echo - GPU - OS - BIOS
echo - BOOT TIME - NETWORK - ALL (for full report)
echo.
echo Type "EXIT" to quit.
echo -----------------------------------------------------
echo.
:: Prompt user for choice
set /p choice="Your Choice: "
:: Process User Choice
if /i "%choice%"=="GPU" goto getGPU
if /i "%choice%"=="CPU" goto getCPU
if /i "%choice%"=="RAM" goto getRAM
if /i "%choice%"=="DISK" goto getDisk
if /i "%choice%"=="OS" goto getOS
if /i "%choice%"=="BIOS" goto getBIOS
if /i "%choice%"=="BOOT" goto getBootTime
if /i "%choice%"=="NETWORK" goto getNetwork
if /i "%choice%"=="ALL" goto getAllInfo
if /i "%choice%"=="EXIT" exit
echo :/ Hmm, I didn’t catch that. Try again!
pause
goto mainMenu
:getGPU
cls
echo -----------------------------------------------------
echo :) GPU INFORMATION :)
echo -----------------------------------------------------
wmic path win32_videocontroller get name, driverversion
echo.
echo Press any key to go back to the main menu.
pause >nul
goto mainMenu
:getCPU
cls
echo -----------------------------------------------------
echo :) CPU INFORMATION :)
echo -----------------------------------------------------
wmic cpu get name, maxclockspeed, numberofcores, numberoflogicalprocessors
echo.
echo Press any key to go back to the main menu.
pause >nul
goto mainMenu
:getRAM
cls
echo -----------------------------------------------------
echo :) RAM INFORMATION :)
echo -----------------------------------------------------
systeminfo | findstr /C:"Total Physical Memory" /C:"Available Physical Memory"
echo.
echo Press any key to go back to the main menu.
pause >nul
goto mainMenu
:getDisk
cls
echo -----------------------------------------------------
echo :) DISK SPACE INFORMATION :)
echo -----------------------------------------------------
for /f "skip=1 tokens=1,2 delims= " %%A in ('wmic logicaldisk where "drivetype=3" get DeviceID^, Size^, FreeSpace') do (
set /A TotalSpace=%%B/1048576
set /A FreeSpace=%%C/1048576
echo Drive %%A - Total: %TotalSpace% MB, Free: %FreeSpace% MB
)
echo.
echo Press any key to go back to the main menu.
pause >nul
goto mainMenu
:getOS
cls
echo -----------------------------------------------------
echo :) OPERATING SYSTEM INFO :)
echo -----------------------------------------------------
systeminfo | findstr /B /C:"OS Name" /C:"OS Version" /C:"System Type"
echo.
echo Press any key to go back to the main menu.
pause >nul
goto mainMenu
:getBIOS
cls
echo -----------------------------------------------------
echo :) BIOS INFORMATION :)
echo -----------------------------------------------------
wmic bios get name, version, serialnumber
echo.
echo Press any key to go back to the main menu.
pause >nul
goto mainMenu
:getBootTime
cls
echo -----------------------------------------------------
echo :) LAST SYSTEM BOOT TIME :)
echo -----------------------------------------------------
wmic os get lastbootuptime | findstr /B /C:"2"
echo.
echo Press any key to go back to the main menu.
pause >nul
goto mainMenu
:getNetwork
cls
echo -----------------------------------------------------
echo :) NETWORK CONFIGURATION :)
echo -----------------------------------------------------
ipconfig | findstr /C:"IPv4 Address" /C:"Default Gateway" /C:"Subnet Mask"
echo.
echo MAC Address:
wmic nic where "netenabled=true" get name, macaddress
echo.
echo Press any key to go back to the main menu.
pause >nul
goto mainMenu
:getAllInfo
cls
echo =====================================================
echo :) FULL SYSTEM INFORMATION REPORT :)
echo =====================================================
echo.
call :getGPU
call :getCPU
call :getRAM
call :getDisk
call :getOS
call :getBIOS
call :getBootTime
call :getNetwork
echo :)
echo Thanks for using the tool! Press any key to return to the main menu.
pause >nul
goto mainMenu
because for now i only know "@echo off" and "start [insert directory]" i am desperate please.
oh and also "Color"
So I'm making a batch file that checks for error and does maintenance, etc. And I want it to automatically run mdsched.exe without the menu popping up, so automating it. But I can't find any way to do it. Is there a way to run mdsched.exe from a batch file without needing user interaction?
im trying to have a code that does this: if file exists, delete it and move on, else, just go on, and keep doing that. but when i tried to make it, it didnt work saying The syntax of the command is incorrect.
ive attatched my code below:
:cleanup
echo cleaning up no longer needed mods
cd "%instance%\mods"
if exist test1.txt (
del test1.txt
)
if exist test2.txt(
del test2.txt
)
please help!
I can't seem to figure out how to fix this tractor will not start even if you get all the correct items
:a10barn
cls
echo.
echo What do you want to check first?
echo.
echo 1. The Fuel Tank. 2. The flywheel. 3. The Transmission 4. The carborator 5. The engine 6. Battery 7. Go to Toolshed first instead. 8. Try to start Farmall Super H
echo.
set /p a10barn=
if %a10barn%== 1 goto a11fueltank
if %a10barn%== 2 goto a11flywheel
if %a10barn%== 3 goto a11transmission
if %a10barn%== 4 goto a11carborator
if %a10barn%== 5 goto a11engine
if %a10barn%== 6 goto a11battery
if %a10barn%== 7 goto a11toolshed
if %a10barn%== 8 goto startfarmallsuperh
else goto a10barn
:a11fueltank
cls&if %15galfueltank% geq 1 goto a11transmissionfixed
echo.
echo The fuel tank is rotted out you will need x1 "Fuel Tank 15 Gallon" from the shop or the toolsheds storage to crank the tractor.
echo.
echo What do you want to check next? 1. The Fuel Tank. 2. The flywheel. 3. The Transmission 4. The carborator 5. The engine 6. Battery 7. Toolshed
echo.
set /p a11fueltank=
if %a11fueltank%== 1 goto a11fueltank
if %a11fueltank%== 2 goto a11flywheel
if %a11fueltank%== 3 goto a11transmission
if %a11fueltank%== 4 goto a11carborator
if %a11fueltank%== 5 goto a11engine
if %a11fueltank%== 6 goto a11battery
if %a11fueltank%== 7 goto a11toolshed
else goto a11fueltank
:a11flywheel
cls&if %Hammers% geq 1 goto a11flywheelfixed
echo.
echo The flywheel is stuck! You will need a hammer to fix it.
echo.
echo What do you want to check next? 1. The Fuel Tank. 2. The flywheel. 3. The Transmission 4. The carborator 5. The engine 6. Battery 7. Toolshed
echo.
set /p a11flywheel=
if %a11flywheel%== 1 goto a11fueltank
if %a11flywheel%== 2 goto a11flywheel
if %a11flywheel%== 3 goto a11transmission
if %a11flywheel%== 4 goto a11carborator
if %a11flywheel%== 5 goto a11engine
if %a11flywheel%== 6 goto a11battery
if %a11flywheel%== 7 goto a11toolshed
else goto a11flywheel
:a11transmission
cls&if %Wrenchs% geq 1 goto a11transmissionfixed
echo.
echo The transmission is stuck in "Reverse Gear", to fix this you manually have to turn the Transmission to "Nuetral", you will need Wrench Size 2 to manually turn the Transmission.
echo You can find it the the toolshed if you have it.
echo What do you want to check next? 1. The Fuel Tank. 2. The flywheel. 3. The Transmission 4. The carborator 5. The engine 6. Battery 7. Toolshed
echo.
set /p a11transmission=
if %a11transmission%== 1 goto a11fueltank
if %a11transmission%== 2 goto a11flywheel
if %a11transmission%== 3 goto a11transmission
if %a11transmission%== 4 goto a11carborator
if %a11transmission%== 5 goto a11engine
if %a11transmission%== 6 goto a11battery
if %a11transmission%== 7 goto a11toolshed
else goto a11transmission
:a11carborator
cls&if %Wrenchs% geq 1 goto a11carboratorfixed
echo.
echo The carborator is clogged, you will need a "Wrench Size 4" to unscrew the hose clamps.
echo What do you want to check next? 1. The Fuel Tank. 2. The flywheel. 3. The Transmission 4. The carborator 5. The engine 6. Battery 7. Toolshed
echo.
set /p a11carborator=
if %a11carborator%== 1 goto a11fueltank
if %a11carborator%== 2 goto a11flywheel
if %a11carborator%== 3 goto a11transmission
if %a11carborator%== 4 goto a11carborator
if %a11carborator%== 5 goto a11engine
if %a11carborator%== 6 goto a11battery
if %a11carborator%== 7 goto a11toolshed
else goto a11carborator
:a11engine
cls&if %Bottleofrustremover% geq 1 goto a11enginefixed
echo.
echo The engine block is starting to get some surface rust, all you need is a "Bottle of Rust Remover", you probably have it in the shed.
echo What do you want to check next? 1. The Fuel Tank. 2. The flywheel. 3. The Transmission 4. The carborator 5. The engine 6. Battery 7. Toolshed
echo.
set /p a11engine=
if %a11engine%== 1 goto a11fueltank
if %a11engine%== 2 goto a11flywheel
if %a11engine%== 3 goto a11transmission
if %a11engine%== 4 goto a11carborator
if %a11engine%== 5 goto a11engine
if %a11engine%== 6 goto a11battery
if %a11engine%== 7 goto a11toolshed
else goto a11engine
:a11battery
cls&if %BatteryTester% geq 1 goto a11batteryfixed
echo.
echo The battery needs to be tested, use a "Battery Tester" to test your battery. You might have one in your toolshed.
echo What do you want to check next? 1. The Fuel Tank. 2. The flywheel. 3. The Transmission 4. The carborator 5. The engine 6. Battery 7. Toolshed
echo.
set /p a11battery=
if %a11battery%== 1 goto a11fueltank
if %a11battery%== 2 goto a11flywheel
if %a11battery%== 3 goto a11transmission
if %a11battery%== 4 goto a11carborator
if %a11battery%== 5 goto a11engine
if %a11battery%== 6 goto a11battery
if %a11battery%== 7 goto a11toolshed
else goto a11battery
:a11transmissionfixed
cls&set transmissionstartfsh=1
echo.
echo You have the correct parts to fix the Transmission! Press 1 to fix.
echo.
set /p fix=
if %fix%== 1 goto a10barn
:a11flywheelfixed
cls&set flywheelstartfsh=1
echo.
echo You have the correct parts to fix the Flywheel! Press 1 to fix.
echo.
set /p fix=
if %fix%== 1 goto a10barn
:a11batteryfixed
cls&set batterystartfsh=1
echo.
echo You have the correct parts to fix the Battery! Press 1 to fix.
echo.
set /p fix=
if %fix%== 1 goto a10barn
:a11carboratorfixed
cls&set carboratorstartfsh=1
echo.
echo You have the correct parts to fix the Carborator! Press 1 to fix.
echo.
set /p fix=
if %fix%== 1 goto a10barn
:a11enginefixed
cls&set enginestartfsh=1
echo.
echo You have the correct parts to fix the Engine! Press 1 to fix.
echo.
set /p fix=
if %fix%== 1 goto a10barn
:a11fueltankfixed
cls&set fueltankstartfsh=1
echo.
echo You have the correct parts to fix the Fuel Tank! Press 1 to fix.
echo.
set /p fix=
if %fix%== 1 goto a10barn
:a11toolshed
cls
echo.
echo This place is a mess, I have to clean it before I can find any tools. Press 1 to load.
echo.
set /p a11toolshed=
if %a11toolshed%== 1 goto loadtoolshed
else goto a11toolshed
:loadtoolshed
cls
echo Loading Complete, press 1 to continue.
set Wrenchs=3
set Hammers=1
set Nuts=16
set Washers=9
set BatteryTester=0
set Tirepump=0
set Bottleofrustremover=1
set 15galfueltank=0
set /p load=
if %load%== 1 goto toolshed
:toolshed
echo.
echo You have %Wrenchs% wrenchs, %Hammers% hammers, %Nuts% nuts, %Washers% washers,
echo %BatteryTester% battery testers, %Tirepump% tirepumps, %15galfueltank% 15 gallon fuel tanks, and %Bottleofrustremover% Bottles of rust remover.
echo.
echo Go to? 1. Barn 2. Shop
echo.
set /p toolshed=
if %toolshed%== 1 goto a10barn
if %toolshed%== 2 goto shop
else goto toolshed
:startfarmallsuperh
cls
if fueltankstartfsh==1
if batterystartfsh==1
if carboratorstartfsh==1
if enginestartfsh==1
if flywheelstartfsh==1
if transmissionstartfsh==1
echo Press 1 To Start
echo.
set /p starting=
if %starting%==1 goto fsh
else goto a10barn
:fsh
cls
echo test
echo.
set /p fff=
if %fff%== 1 goto startfarmallsuperh
Hello,
I am trying to make a script that will copy all of the new (and new version) files from a thumb drive to the C drive.
It should work on different computers with different drive mappings and letters, and therefore I need to check which drive the USB is assigned to. Chat GPT came out with the following solution but it doesn't work if the drive is not D but E.
u/echo off
set folderName=XSIM student
set destination=C:\%folderName%
rem Initialize the source variable
set source=
rem Check drive D first
if exist D:\%folderName% (
set source=D:\%folderName%
goto found
)
rem Loop through potential drive letters E to Z
for %%d in (E F G H I J K L M N O P Q R S T U V W X Y Z) do (
if exist %%d:\%folderName% (
set source=%%d:\%folderName%
goto found
)
)
:found
if not defined source (
echo USB drive with the folder %folderName% not found.
pause
exit /b
)
echo Source found: %source%
echo Copying new or updated files from "%source%" to "%destination%"
robocopy "%source%" "%destination%" /E /XO
if errorlevel 1 (
echo Copy operation completed with warnings or errors.
) else (
echo Copy operation completed successfully.
)
echo Script finished. Press any key to close.
pause
How can I solve the issue?
Thanks!
First let me say I am new to using batch files , and want thank anyone for their help. I have simple file to open a network stream with VLC. I have a file for each stream. I would like to make a file to open 4 or 5 VLC streams on screen at once, Does not work if I just repeat script, 2nd will open VLC but always fails stream. Is what I am trying to do possible? And if so, how do I write it to open them in certain spots on screen instead of on top of each other.