All Questions
Tagged with batch-file batch
64 questions
0
votes
1
answer
656
views
How can I redirect the output of one command in a batch file?
Edit: This question has been answered, please scroll down ⬇️
This question is related to Server Fault because I am automating minifying some web files before deploying them to my server.
So I have a ...
0
votes
1
answer
408
views
Looking for a way to replace every instance of a non-zero sized file in a directory tree using a batch file
I am trying to figure out a way to have a batch script overwrite every instance of a non-zero byte file inside of a specific directory and its sub-folders. I'm guessing since I'm looking for a non-...
1
vote
1
answer
7k
views
Batch - Extract string before the specified character
How to get the string before the character hyphen? The following code gets the string after the hyphen. How can I reverse this?
set string=1.0.10-SNAPSHOT
echo %string:*-=%
SNAPSHOT
But I want the ...
0
votes
0
answers
886
views
Extracting multiple password-protected archives located in multiple sub-directories
There is a folder that contains many folders and subfolders, and each of these contains any number of password-protected 7zip archives. The password is the same for all of them. These are single-layer ...
1
vote
0
answers
611
views
using start /wait for a headless process in a batch file - any way to show the process is running?
So I have a large batch file, and in the middle it hits a start /wait command to run a silent install of an MSI. I'd like to have some animation or something to indicate that the batch file is in fact ...
3
votes
3
answers
3k
views
How to get all processes under a session of a particular process that is using a port in Windows cmd
I want to list and kill all processes belonging to a session of a particular process that is using a port. This should happen through a windows batch command that would accept a port number as input.
...
0
votes
1
answer
4k
views
Get the previous day date as variable in batch file from powershell command output
The scenario is like this. I need a previous day date (i.e. Today -1) as variable in a batch file. But if previous day is Sunday (i.e. script running on Monday) it should return the Saturday's date (i....
0
votes
1
answer
274
views
can you sum within a function or use '!' within '!' in cmd?
Having some difficulty with the delayedexpansion in cmd.
This might be a stupid question but is there any way of summing within a function (ie without 'set') or using ! within ! (or something to ...
1
vote
1
answer
4k
views
Windows batch file scripting: how to get directory named with latest date (yyyy-mm-dd format)?
I have a directory with many subdirectories. Each subdirectory is named with the yyyy-mm-dd format. I'm writing a Windows batch file and I need to grab the directory name with the most recent date and ...
3
votes
1
answer
2k
views
Windows Command - Delayed Expansion Syntax to Echo The VALUE of a Variable That Contains Another Number Variable
I am trying to echo the VALUE of a variable whose name contains another variable ($project!$project_number!_control) while using delayed expansion. I can't figure out the syntax to do this. Here's ...
0
votes
1
answer
2k
views
Pass PIDs from tasklist and kill processes with tasklist WITH spaces in the name of the process
So this question is VERY similar to this question, with this answer. But some of my processes have a space in the name, and CMD returns nothing. My original question has been answered in this answer, ...
19
votes
3
answers
113k
views
call batch file and run using its own path/directory
I have a batch files that calls other batch files like this:
e:\foo\master.bat has the content:
call e:\bar\run1.bat
and e:\bar\run1.bat has the content
app1.exe
the problem is that when I run ...
1
vote
1
answer
1k
views
Why my choice batch command always selects first integer choice?
I created a simple menu of choices of numbers like the following:
@echo off
CLS
:MENU
ECHO.
ECHO ...............................................
ECHO PRESS 1, 2 OR 3 to select your task, or 4 to EXIT....
-1
votes
2
answers
281
views
How to create a batch file which after some time execute a file but if interrupted execute another?
I want to automate my ms office installation 2007 or 2010 running a batch file.
I am thinking having an options menu 1.Office 2007 2.Office2010
When started I want my timer to start..lets say 20secs
...
0
votes
1
answer
38
views
Alternative to SWARM FTP batch processing?
In a proposed project the plan is to divide large data sets into chunks, expose them by SFTP into a swarm CPU type of LAN cluster architecture for processing of historical numerical and financial data ...
2
votes
1
answer
36k
views
Run a batch file from network shared folder depending on MS outlook bit version
Hello I'm trying to figure out on how to Run a file from network, basically it's located from \10.18.xx.xx\installers\install.bat, so yeah It's gonna prompt a username and password when I locate it ...
4
votes
1
answer
29k
views
Script for renaming files and adding a timestamp (server 2012 r2)
I'm struggling to create a (fairly simple) batch file script that meets these requirements:
Looks in the folder called Source for a file (with any name.csv)
Renames the file to ...
0
votes
1
answer
175
views
DOS Set variable only available after execution
I have a very simple script that I want to take a value from a text document (single line, one value) and pass it to taskkill - it needs to be a one liner too so I have:
set /p pidtokill=<C:\temp\...
0
votes
1
answer
109
views
Displaying dirsize in batch file windows server 2012 R2
I'm trying to display the dirsize with a batch file but so far no luck. DU, dirsize gives me a not recognized as an internal or external command error.
This is my batch file so far, it displays all ...
3
votes
2
answers
23k
views
Robocopy - All data marked as modified
We make use of the following script to backup a folder (quite large - approx. 400GB), to a NAS with EXT4 Filesystem:
robocopy "Source_Directory" "\\NAS\Destination\Directory" /MIR /FFT /COPYALL /W:5 /...
1
vote
2
answers
1k
views
Difference between 'call perl script.pl' vs 'call script.pl' on Windows
On Windows servers (I've tested 2008 R2 and 2012 R2) we noticed different behavior in execution of Perl scripts that are called from batch.
Consider a primitive batch file as follows:
:beginlbl
call ...
2
votes
1
answer
1k
views
how to loop though sub folder to check if folder is empty - batch script?
What I want to do:
write a batch script to do the following
loop though all dir starting with "01-"...
Check if "Pictures" folder is empty or not. skip rest folders
If "Pictures" folder is Empty, ...
1
vote
1
answer
398
views
How can I confiuger a windows service from the command line
I have a windows service that I've written. I'd like to make it easy for my server team to install it. So I'm building a little batch script.
One of the things that I require is for it to be setup ...
1
vote
2
answers
152
views
windows - how to make some file impossible to remove/rename for all users via commandline
how to (using command-line/batch file only) make some file impossible to delete/rename for all users. I tried attrib +R on file itself and on directory where it exist but it doesn't help
1
vote
1
answer
2k
views
copy file with date appended
I am writing a script that copies files to another directory. I wanted to append the date to the end of the file but when I try to use %date% I get the following:
copy c:\mydir\file.zip "c:\temp\...
1
vote
1
answer
2k
views
How to catch "The system cannot find the file" within For /F loop?
How to catch "The system cannot find the file" within For /F loop?
I would like my code to do the following:
1 - Search for the specified file
2 - If file not found, handle the "The system cannot ...
2
votes
1
answer
3k
views
how can I download web pages from the command line in windows
Well, I'm trying to do some automation using batch file to speed up my daily routine at work, and I need to solve these little questions:
I want to install wget command, but using only the pure ...
0
votes
1
answer
337
views
How to change AWSTATS configuration via cli
My Apache log files have the date included in the name and I can't change this. Is there a way to change the LogFile config parameter for AWSTATS using Windows CMD prompt? Better yet a batch script? ...
2
votes
0
answers
280
views
DSADD in batch file - syntax incorrect! Same command in command works fine
Really stumped here and I'm sure the answer is simple. Simply put, I'm creating a bunch of AD accounts based on input from a spreadsheet. I've been able to concatenate the fields into a DSADD command ...
4
votes
2
answers
2k
views
Is there a way to change passwords on multiple servers simultaneously?
x3 Server 2012 R2, x2 Server 2012
My system has 5 servers; 1 Hyper-V server hosting 2 vm servers (these are the x3 2012 R2 servers), and a Win 8.1 pc running hyper-V that hosts 2 more vm servers (...
2
votes
3
answers
12k
views
How to see what last batch was run on windows
Is there a way to see what was the last batch (something.bat) run on windows? I was in a folder which contains lots of batches, as I was opening them one by one by right clicking and selecting notepad+...
0
votes
1
answer
874
views
Batch script to increment the text file ans also the value inside the file [closed]
I have a text file Foo.txt which contains value content0.
I have to create a batch file which increment the text file like Foo1.txt, Foo2.txt.....Foo5.txt and also the values in the file content1, ...
0
votes
2
answers
2k
views
Bat script start a program and than restart
I need some help creating a .bat script that starts a program and when done it restarts the computer.
cmd /c C:\"Program Files"\"Toolwiz Time Freeze"\ToolwizTimeFreeze.exe /usepass=password /...
2
votes
1
answer
2k
views
How to remove directories using wildcards by reading a file using batch?
Batch file
for /f "delims=" %%f in (7profiledeletelist.txt) do rd /s /q "%%f"
PAUSE
exit
7profiledeletelist.txt
C:\Users\1*
C:\Users\2*
C:\Users\3*
C:\Users\4*
C:\Users\5*
C:\Users\6*
C:\Users\7*
C:...
-1
votes
1
answer
1k
views
Best Practices for User folder permissions [closed]
The following is my bat file. Is there a way I can substitute First.Last with usernames from a CSV file? My boss doesn't want to do all the users at once. He's afraid that something may happen so he's ...
0
votes
1
answer
220
views
I am unable to set the owner of a folder back to the user from my bat file
The following bat file is being used to fix permissions for Users in our organization.
Everything works perfectly until we try to set the owner back to the user.
takeown /F F:\Users\First.Last /R
...
0
votes
0
answers
2k
views
Error: "Parameter is incorrect" when opening 0b bat/cmd
Having sort of issue that is more likely annoying when need to create short batch script (though it's not scripting issue).
I want to right-click on desktop and create new text file. Rename it and ...
1
vote
1
answer
2k
views
Running multiple instances of a Batch file in windows simultaneously?
I have a windows batch file that is invoked by windows scheduler. When I try to have multiple windows scheduler tasks trying to run the batch file simultaneously, the batch file is locked by the first ...
3
votes
1
answer
3k
views
batch - File last modification time with seconds
I want to know when a file has been modified for the last time.
I can get these infos using the following batch script:
FOR %%i IN (myfile) DO SET modif_time=%%~ti
The problem is how to get the ...
0
votes
1
answer
2k
views
Batch script - How to release a locked file for batch 'copy'
A daily windows scheduled task triggers a batch script which moves program files to a folder on a server, using a simple copy routine.
rem deploy programfiles
copy dailybuild\*.dll "\\myserver\...
0
votes
1
answer
2k
views
.bat file - Nagios v3.2 service check and start if stopped
I'm just barely getting into programming so I do apologize for my ignorance. I'm trying to create a .bat file that will check if a service is running on XP Pro.
If service is running it will exit 0.
...
0
votes
2
answers
2k
views
Batch File to Loop Through Folders and Process If Specific File Found
I have a large number of websites running the same CMS that I want to update as a batch. As the update process just requires copying the updated files into the folder of the given sites, a batch ...
0
votes
1
answer
1k
views
Windows batch find folder if statement
Assume a file system with the following format
Folder A
--->Folder 1
--->Folder 2
--->Folder 3 etc..
Folder B
--->Folder 4
--->Folder 2
--->Folder 3
Folder C
--->Folder 1
--->Folder 2
--->Folder 3
---...
2
votes
1
answer
7k
views
Batch - how to copy file by minimum size and date modification?
I have this simple batch script which copies the newest file in some dir to another place.
I want this script to also ignore all files (in the DIR command section) under 1GB of size.
FOR /F "delims=|"...
1
vote
2
answers
14k
views
RoboCopy A File From The Web?
Is it possible to download a file from the web using RoboCopy? What would the syntax for that be? Here's what I'm trying:
RoboCopy "http://www.google.com/" "C:\some_folder\" "index.html" /L /V /E /...
2
votes
4
answers
9k
views
How can I hide ms-dos window when running a .bat file?
I am running a .bat file for my script (Scheduled Tak (CronJob)) per minute. When it run, seems ms-dos window short period of time. My batch code like this;
@ECHO OFF
C:\wamp\bin\php\php5.4.3\php.exe ...
209
votes
5
answers
661k
views
How to sleep in a batch file?
How to pause execution for a while in a Windows batch file between a command and the next one?
9
votes
3
answers
66k
views
How can I create an ODBC connection from .bat file in Windows?
I need a batch script to create an ODBC/DSN connection from a .bat file in Windows. How can I do this?
2
votes
3
answers
3k
views
Using a for loop in Microsoft cmd.exe, how can I process only the files with a certain extension?
I have a the folder c:\test\ and two files in it a.txt and b.txtv.
I would like to process just the files with extension equal to .txt.
If I write this commands
cd c:\test
for %f in (*.txt) do echo ...
1
vote
1
answer
2k
views
batch file infinite loop when parsing file
EDIT: Apparently I don't have enough rep to answer my own question, so the answer is going here.
OKAY!
SO! I didn't exactly solve the problem... but I stopped using cacls.exe and started using ...