Questions tagged [batch-file]

A batch file is a text file containing a series of commands that are executed by the command interpreter on MS-DOS, IBM OS/2, or Microsoft Windows systems.

Filter by
Sorted by
Tagged with
0 votes
1 answer
5 views

BAT script Time formatting and 3 blanks at the end of string

I have a Windows batch script where I need time in HH:mm:ss format. I tried following but no matter what, it inserts 3 blanks or may be spaces at the end of the %time% string. %time:~0,8% %time:~0,2%:...
user avatar
  • 4,552
0 votes
0 answers
13 views

Batch Command to Search network Folder by date modified

I am attempting to find the most recent files in a network folder using a wild card. The code within the batch file is provided below. When the .bat file is executed it returns an error for /f %%f ...
user avatar
0 votes
0 answers
15 views

.BAT command shell script requires keyboard Enter to resume when PC wakes

Windows 7, 10, 11. I run a .BAT stats collector command line script (as administrator) in a loop that does a variety of things including delaying for 30 seconds with ping -n 30 127.0.0.1 > DUMMY....
user avatar
  • 1
0 votes
0 answers
29 views

Need to automate cleanmgr silently with the "Clean Up System Files" [closed]

This has been a very difficult undertaking. I am trying to write a script (bat or powershell) that will silently clean up everything you see in cleanmgr BUT with the "Clean Up System Files" ...
user avatar
  • 1
0 votes
2 answers
16 views

How to get the shortest token from a CSV variable in batch?

Here's my code: set csv="Desk,House,Car,Animal,Existentialism" for /F "tokens=* delims=," %%a in ("%csv%") do ( set token=%~1 echo "%token%" ) This ...
user avatar
  • 21
0 votes
1 answer
20 views

How to cleanly format multiple if statements in a batch file?

This script works: IF EXIST %PublishRoot%\ConnectionStrings.json IF EXIST %PublishRoot%\Settings.json IF EXIST %PublishRoot%\Web.config ( call DeployInit %1 exit /b ) But it's not readable. I ...
user avatar
  • 21
5 votes
3 answers
55 views

Copying Files with Certain Names and ascending numbers from a List

I have a folder with a few thousand pdf files that are named a certain way and a list of files I want to copy to another folder. - "abcd0000000001-00.pdf" - "abcd0000000001-01.pdf" ...
user avatar
0 votes
0 answers
14 views

Automatically Open a File when A certain directory is opened in Windows Explorer

Is it possible to open a certain text file or a file with specific extension, when I open a particular directory in Windows Explorer in Windows 10? Here is one possible scenario for this request: I ...
user avatar
0 votes
0 answers
31 views

How is a batch file (`.cmd` / `.bat`) file executed on Windows?

Context On Windows, the application responsible for opening a given file type (identified by its extension) is resolved using file associations defined (among a few other places) in HKEY_CLASSES_ROOT. ...
user avatar
  • 21
1 vote
0 answers
14 views

why windows registry batfile shell key overwrites value during bootup [HKEY_CLASSES_ROOT\batfile\shell] [closed]

I am given a new windows10 Enterprise (20H2) HP laptop for my new job. When system boot-up, everytime it sets following registry value: When this key is set to "edit" as shown above, files ...
user avatar
0 votes
1 answer
34 views

If exist folder batch not working

Please help to rectify my batch code where goes wrong. The purpose is to check where the folder is then delete those files older than 180 days. When It runs, it does not pop up anything. @echo off ...
user avatar
  • 45
1 vote
1 answer
79 views

How to clear message sent by echo command

My batch informs the user when the value entered is wrong and offers two options: retype the value or exit the program. @echo off cls setlocal enabledelayedexpansion set /p _Value=Enter the value: ...
user avatar
  • 375
0 votes
1 answer
31 views

How to stop a batch file altogether from a child batch file?

I have a couple of batch files. One is the parent and others are children that are called by the parent. Let's say I have Deploy.bat that calls ExtractParameters.bat. In ExtractParameters.bat I want ...
user avatar
  • 21
0 votes
1 answer
22 views

Why parts of my script run more than once?

I'm trying to find a line from a given CSV file, and parse it. Here's my script. It's in Extract.bat: @echo off findstr "%DomainName%" C:\LocalSecrets\Deployment.csv > /Temp/Found set ...
user avatar
  • 21
0 votes
1 answer
13 views

Choice command only returns errorelevel=0 inside a nest of if's

I execute the call choice command inside an IF's nest, but it only returns "errorlevel=0". When I run out of if's it works correctly and returns the value 1 when I select y=yes. I used the ...
user avatar
  • 375
0 votes
1 answer
17 views

How to store the result of a subquery in a variable in cmd?

Here's my bat file: @echo off for /F "tokens=* delims=," %%a in ('type C:\LocalSecrets\Depolyment.csv ^| findstr "%DomainName%"') do call :parcsv %%a goto :EOF :parcsv echo &...
user avatar
  • 21
2 votes
1 answer
52 views

How to download a file from multiple Linux machines using WinSCP or batch script?

I need to download a specific file from 40 different Linux machines. How can I achieve using single script? I tried WinSCP.com /script=script.txt Here the limitations is only one session can me make ...
user avatar
  • 21
0 votes
1 answer
42 views

Can not copy .bat file from network share

This is so bizarre to me. I have a .bat file sitting on a domain-joined workstation, let's call it Origin. Workstation is running Win10 21H2. I have another workstation, let's call it Target, also ...
user avatar
  • 420
0 votes
2 answers
38 views

How to open appwiz.cpl with a preconfigured search input?

As part of my job I install a suite of software, and frequently find myself uninstalling one element or another to test latest versions. Each of the programs is installed under a different name, but ...
user avatar
0 votes
0 answers
11 views

Powershell session chaining in bat file

What I want is to run a .py file after activating the virtual environment. What I did @echo off PowerShell -c "conda activate base | python C:\Users\test.py" but it does not work
user avatar
  • 1
0 votes
0 answers
11 views

Delete folders with specified folder names old than certain days old [duplicate]

I want to delete some folders with special name format yyyy-mm-dd only using following code but it does not work. Please help to rectify. FORFILES /p “d:\testing” /S /m *-*-* /D -10 /C “cmd /c IF @...
user avatar
  • 45
0 votes
2 answers
43 views

Error running and killing then run new batch file on specific time period

Error running and killing then run another batch file on specific time period. Tried to run timeout and CALL simultaneously but I guess there's an error in my lines so it doesnt go through. Since my ....
user avatar
0 votes
0 answers
32 views

Creating a Batch File for folder creation

What I'm looking to do is in two parts: Create subfolders within a folder and name them, these names are usually long (account names) so any way to have them be imported from a word or excel doc ...
user avatar
0 votes
1 answer
34 views

Echo errorlevel description to log file

Forgive me ignorance here. I'm very new to writing batch files. I am copying files from one mapped server drive to a different mapped server drive, and creating a log file after the copy is complete. ...
user avatar
  • 1
0 votes
0 answers
19 views

Calling a routine inside if doesn't return value only the first time but later values are returned in batch programming

My question is that why doesn't the first returned value show or appear. Values are returned from second time and so on. This is a simple example of the problem. @echo off SETLOCAL=...
user avatar
1 vote
1 answer
20 views

Pass password variable to manage-dbe

I need a batch program .bat to pass prompted password to manage-bde -unlock -pw. Tried this unlock.bat with password devel! @ECHO OFF :GetID set "id=" set /P id=Enter id: cmd /k manage-bde -...
user avatar
  • 11
1 vote
1 answer
31 views

Add file name to beginning and line break at the end of file

I want to add file name to the beginning of every file and line break (-------------------------------------------------------) --> like this --> empty ...
user avatar
  • 113
1 vote
0 answers
32 views

7-zip - mutiple folders in seperate archives

I most likely found the answer to my question in this Thread: How to make 7-zip do a whole bunch of folders The user @Enteleform posted an answer and a script in there to create a batch file to drag ...
user avatar
  • 11
0 votes
2 answers
39 views

bat script 'for /F' loop filtered results

I need a .bat for /f loop that will reclusively list only specified filenames from all folders (+any sub-folders) - eg 20220103_1603-Picture 1.jpg, 20100523_0900-Picture_outdoors.png, 20110901-Image ...
user avatar
  • 11
1 vote
1 answer
30 views

I want to collect system information using bat file

I hope you all are doing well. Help me please. I want to collect system information using bat file like: List of Software OS information System Hardware details. I had some code which collects the ...
user avatar
0 votes
0 answers
70 views

Windows: command line how to unzip file and rename it's content with zipped file name in current folder and sub folder?

I would appreciate if I got help on this, I have the following script that unzip and rename the content with zipped file name, however it works in the current folder only, I need it work in subfolders ...
user avatar
  • 1
0 votes
2 answers
47 views

IF cancels when I run message command to user

Windows 10 x64 system I made a batch file that checks audio file extensions inside a folder. When I run the command that will send the alert message outside the IF statement, the message is displayed ...
user avatar
  • 375
0 votes
0 answers
45 views

how to detect user press right arrow key from cmd(.bat) or powershell and make if-else

if user press "right arrow key" i need to go to next page. if press "left arrow key" how can i detect if anyone pressing arrow keys and navigate them. Example: (if right arrow ...
user avatar
0 votes
1 answer
54 views

Batch: Copy, then delete, files from list; need error handling

I've looked through the many batch-from-a-list topics on here, but haven't found anything on point. I have a text file with a list of files, including paths. I need to first copy these files out to an ...
user avatar
0 votes
0 answers
25 views

Regex to remove text after some string or some character

I use a batch code to rename some files. I have this situation thg 2013# ajjogj ggeg 2013# gtkhj ijhhi I want to get this thg 2013 ggeg 2013 I try to set this code to remove text after 2013# for %%a ...
user avatar
0 votes
1 answer
22 views

APPDATA in .bat or .cmd does not print proper name with space

I have different users that have name with space and no space : John Doe, Jane Susy I tried typing %APPDATA% in command prompt, and all i get is John / Jane. How should i script my batch/cmd file, so ...
user avatar
0 votes
0 answers
31 views

Merge the multipage tiff in subfolder to another output folder as single image

Iam trying to merge the multipage tiff in subfolder to another output folder as single image. the base command is convert f:\input*.tif f:\output\image1.tif My question : Iam getting no output. What ...
user avatar
0 votes
1 answer
37 views

Replicate GUI behavior when opening an explorer window with command line in Windows 10?

If I double click a shortcut to a folder and open that folder, then I double click the same shortcut again, Windows doesn't open a second instance of the folder, it activates (or maximizes) the folder ...
user avatar
  • 395
0 votes
1 answer
37 views

need to create a batch file to run at logon of each user to check for folder with its user ID in path & create if not ther, apply full control to user

This script creating folder but it is applying permissions to all the users who ever logged into the server. if not exist \\xxxxxxx\userhome$\%username%\ mkdir \\xxxxx\userhome$\%username% || goto :...
user avatar
0 votes
0 answers
24 views

copy files using listed in text file, how to copy files and with folders and it's subfolders

I want to copy several files listed in file.txt file.txt` file contains the relative path: web/main/src/web/login.txt web/main/src/ht/pro.i web/main/src/log/ss.p When I run the following script: @...
user avatar
0 votes
1 answer
153 views

.bat file to change windows password

Reference Image Is there a way to automate the process of changing the windows password using a .bat file. The traditional way of changing the password will be like. Open Command Prompt, type net ...
user avatar
0 votes
1 answer
50 views

Powershell commands aren't running in CMD or .bat

I am trying to put 2 powershell commands into a .bat file so I can just click on the file and run them, without opening powershell, pasting in the commands, etc. The commands are: cd Downloads get-...
user avatar
0 votes
2 answers
46 views

"sendto" all selected files into a folder

I found this lovely time saving script which has helped me a lot. @echo off cd /D "%~dp1" md "%~n1" move %1 "%~dp1%~n1" Script found here Application that will move file ...
user avatar
  • 3
1 vote
1 answer
39 views

Skip a command if it is stuck and continue with the next command without terminating batch job in windows batch script

I have a batch script with multiple commands running sequentially.There is one particular command which takes longer occassionaly(sometimes even stuck for hours). I want to skip this command if its ...
user avatar
0 votes
1 answer
19 views

How to skip argument/parameter when copying files in a batch script?

test.txt contains 4 files with relative path: "brazil\206\tri\read.txt" "brazil\206\tri\log.i" "brazil\207\pass\prog.p" "brazil\206\bin\read.xml" Using ...
user avatar
1 vote
1 answer
29 views

How do I incorporate specified path in batch file for ffmpeg for each?

If I use this using CMD within the directory where all the movies are, it works fine: for %i in (*.mp4) do ffmpeg -i "E:\%i" -map 0 -c copy -metadata:s:a:0 language=eng "E:\converted\%~...
user avatar
0 votes
0 answers
24 views

cmd array populating empty [duplicate]

This is giving me little headache. I fillup an array with ip adresses and hostnames. When filling the array the corresponding element shows added to the array. Data for sentinels.txt: 127.0.0.1 ...
user avatar
  • 1
0 votes
1 answer
82 views

Batch file to use different cmd step by step

I was creating a batch file to continuously work on few process. first I have to create 3 separate folders based on input folders/subfolders than use copy cmd from folder 1 to folder 2 than ...
user avatar
0 votes
1 answer
58 views

windows batch. Checking for a substring in variable gives error. Needs Escaping for space

From https://stackoverflow.com/questions/7005951/batch-file-find-if-substring-is-in-string-not-in-a-file, I figured how to check if PATH variable has a certain substring(groovy's path). However, my ...
user avatar
  • 1,175
0 votes
0 answers
33 views

Need .bat script to copy file to multiple pcs

I have a requirement that I need to copy a file to multiple PCs frequently. It has to first check if the file exists, if yes then rename it with DATE and if no, then copy. I prepared a txt file with ...
user avatar

1
2 3 4 5
57