batch-file

Batch File To Loop Menu

偶尔善良 提交于 2020-01-06 20:24:51
问题 I'm creating a batch file that will launch when I login to my user account. I followed this tutorial to create a batch file with a menu. It works, however, if the user enters a number that is not listed, I want it to go back to the menu. How would I implement that? Side note: I understand I could use something more flexible like Powershell, however, I prefer batch files. Here is what I have so far: @ECHO OFF CLS :MENU echo Welcome %USERNAME% echo 1 - Start KeePass echo 2 - Backup echo 3 -

{BATCH} Random Not Working?

烂漫一生 提交于 2020-01-06 20:03:41
问题 UPDATE Solution Found, working code: @echo off color f0 title Date Of Birth Generator :begin REM Setting Current Year (Year Cannot Surpass Current Year) for /f "tokens=1 delims=-" %%g in ('echo %date%') do ( set cYear=%%g ) REM Year set /a year=(%RANDOM% %% %cYear%) + 1 REM Leap Year Check set /a mod=%year% %% 4 if %mod%==0 ( set jy=1 ) else ( set jy=0 ) REM Month set /a month=(%RANDOM% %% 12) + 1 REM Define The Maximum Days In Random Month if %month%==1 set dm=31 if %month%==3 set dm=31 if

Batch command - adding date at the end of folder

对着背影说爱祢 提交于 2020-01-06 19:42:33
问题 I currently run a batch command to create a folder 1 day in advanced and label it as MMDDYY. Everything is working as intended except single digit days. Currently it named the next day folder has 12214, is it possible to have it name it as 120214? @echo off for /f "tokens=2 delims==" %%a in ('wmic OS Get localdatetime /value') do set "dt=%%a" set "YY=%dt:~2,2%" set "YYYY=%dt:~0,4%" set "MM=%dt:~4,2%" set "DD=%dt:~6,2%" set "HH=%dt:~8,2%" set "Min=%dt:~10,2%" set "Sec=%dt:~12,2%" :loop set /a

Using multiple colors in matrix batch file

隐身守侯 提交于 2020-01-06 19:41:44
问题 I've been messing around with batch files a bit, and have this code running. I did not write it, I found it, and it just runs random blue numbers in command prompt until you exit. My question is this, I want to make one where every character is a random color. so essentially, it'll look like a rainbow vomited skittles on my screen. But i digress. That is my challenge, and so far i have failed at solving it. Any ideas would be great! @echo off color 01 cls :a set /a a=%random% if %a% geq 16384

Batch file that can index and rename files in multiple subfolders, resetting the index every time the loop goes into a new folder

こ雲淡風輕ζ 提交于 2020-01-06 19:30:33
问题 I am in the process of writing a batch file that can quickly run through a root folder, We'll just say "C:\SomeMusic\" that has a lot of subfolders and files in it. What I'm looking to do is to rename just the files in each folder, but in a sequential way (ex. somefile1.ext, somefile2.ext ...) I have this right now, but I do not know how to reset my counter if the loop goes into a new directory SET COUNT=0 setlocal ENABLEDELAYEDEXPANSION FOR /R %%X IN (*.mp3) DO ( SET /A COUNT=!COUNT!+1 SET

If Processor=xx-bit do this in batch?

扶醉桌前 提交于 2020-01-06 17:45:23
问题 I'm trying to write a batch script to execute a certain program depending on the architecture of the system. For example, something like this: If ProcessorArch=64-bit 7zip64.exe If ProcessorArch=32-bit 7zip.exe If ProcessorArch=x86-64-bit 7zipx86-64.exe Thank you 回答1: The value of environment variable PROCESSOR_ARCHITECTURE is always x86 on running 32-bit Windows independent on architecture of the CPU as even on a motherboard with an Intel/AMD x64 processor a 32-bit Windows can be installed

If-else condition in batch file

做~自己de王妃 提交于 2020-01-06 16:32:24
问题 I need to convert next code (C language) condition to batch file: if(version == 1 || version == 2) { // do something } else { // do something other } So in batch file it will be looks like: if "%version%"==1 ( // do something ) if "%version%"==2 ( // do something ) if not "%version%"==1 ( // do something other ) if not "%version%"==2 ( // do something other ) Is there more better way to write it? 回答1: "There is no logic and/or but you can use the mighty goto. if "%version%"=="1" goto :TRUE if

Why don't Windows Shell (cmd.exe) builtin commands read from stdin?

允我心安 提交于 2020-01-06 16:18:10
问题 Why don't Windows Shell (cmd.exe) built-in commands read from stdin? (or so it seems) Example: echo bar | set /p foo= 回答1: SET /P does read the input from the pipe, but it doesn't do any good because both sides of the pipe are executed within new cmd.exe processes. So the newly defined variable is lost once the pipe sub-processes terminate. For more information, see the selected answer to the Stack Overflow question - Why does delayed expansion fail when inside a piped block of code? 来源:

Batch, Can I open a url from a batch script?

我是研究僧i 提交于 2020-01-06 16:01:52
问题 I'll show you what I have then try to explain the question, @echo off Echo put search in front of a question to search for the answer on the internet Set /p question= That's it so far, if the user puts search I front of a question it searches the Internet, I would like it so it is in one batch file as well. Thanks 回答1: If you just want to open the default web browser, it's as simple as using start . This snippet will check to see if your question variable contains "search:" by replacing

Subtract month in Windows batch

对着背影说爱祢 提交于 2020-01-06 15:11:26
问题 I would like to have this run and show the previous month. When I try to subtract the month it makes the last day of the month field not appear. @echo off set FirstDay=01 set Month=%date:~4,2% set Year=%date:~10,4% if %Month%==01 set LastDay=31 & goto foundate if %Month%==02 set LastDay=28 & goto foundate if %Month%==03 set LastDay=31 & goto foundate if %Month%==04 set LastDay=30 & goto foundate if %Month%==05 set LastDay=31 & goto foundate if %Month%==06 set LastDay=30 & goto foundate if