Windows Batch





Batch files are text files containing a script of commands that are executed by the command interpreter on DOS, OS/2 and Windows systems. Most commonly, they are used to perform a series of functions that are repeated -- copying a set of files created daily with one step, for example.

Share tech news, updates, or what's on your mind.

Sign up to Post

Is it possible to include multiple hostnames with this command. Note that this command can be processed as is, in it's simplest form below, from the command line only
systeminfo /S hostname | find "KB3021952"

Open in new window

.  Is there a way to add multiple hostnames to it?
Why would the command below work from the command line but not from PowerShell? From PowerShell, I get the error "FIND: Parameter format not correct" where I do not get that result in the command line. What is the correct PowerShell command? I resolve?
systeminfo /S hostname | find "KB3021952"

Open in new window

can you please help,
I have a folder with couple csv files.
I'm trying to automate this by running a batch to remove the commas & quotes from the files.
The file names are not always the same, but they will always be in the same folder (C:\Users\Wassim\Desktop\POD Updates)

Any help is appreciated,
I have scheduled a batch file to run at a set time every day using the Server 2012 task scheduled.

This task is set to run using a domain administrator account.

The problem is that within the Server 2012 task scheduler I receive a message that says "The system cannot find the path specified (0x80070003)" (see the screenshot).

This domain administrator account has also been granted the right to run batch commands.

What needs to be done to fix this issue so that this batch file will be able to run at the set time everyday without any problems?

System cannnot find the path specified
Dear Support,
i have abat file i want to replace  [ESC] with new line please find the attched sanpshot fro both notpadd++ and notpad
@echo off
 setlocal enabledelayedexpansion
 set InFile=C:\Copy_EJ_Files\EJ_15-02-2016.txt
 set OutFile=C:\Copy_EJ_Files\Temp\EJ_15-02-2016.txt
 if exist "%OutFile%" del "%OutFile%"
 for /f "tokens=1* delims=[
]" %%a in ('type "%InFile%" ^| find.exe /n /v ""') do (
       set Line=%%b
       if defined Line set Line=!Line:-+=-!
       >>"%OutFile%" echo.!Line!
Please note the following command line:

robocopy "\\network path" "C:\local path" /s /e /r:0 /z

Open in new window

It is supposed to copy over the file if there have been changes and erase over it if it exists at its destination!
Is this correct?
Hello experts,

I am looking for a script that:

1. Remove all the files in a result folder, modified in the last 5 minutes and which finished with a _V2" string.

2. Open a Listing.csv  file located in the same folder of the script.

3. Read the files names reported in this Listing.csv

4. If a reported file exists in result folder copy it into request folder and rename each copied file in request folder by adding a "_V2" string.

Log activities:

-If result folder doesn't exist.
-If request folder doesn't exist.
-Files that have been removed.
-Files that have been copied from result folder to request folder.
-If a reported files name hasn't been copied.

If you have questions, please contact me.

Thank you very much for your help.
How would I set up a script or batch file will do the following:
Check the date on a file - if it is 11/6/2015 - do nothing (goto end I assume)
Check the date on a file - if it is 7/30/2015 - do nothing (goto end I assume)
Any other file date, run a command
Just not sure how to do the date checking in a batch file.

If date = XXXXX goto end
if date = XXXXX goto end

delete files
copy files from server

What is the command syntax to install single kb article patches on multiple machines, silently, via Powershell
basically here is the logic.

there are 4 local folders that have data that need to transfer to shares.

on the local machine there are files in 4 folders.


there are 4 shares that user has access to but they are not mapped.
do i have to map them.  He does have permission to them but i would rather not map them.
if mapping is better part then i can do that.

the shares are


I need all contents of the drawer local folder to replace all contents of the drawer shared folder.  There should be 4 files with the exact same name.  I need it to leave files in the destination folder if there is a file in the destination folder  with a different name(the destination folder has a file that the source folder does not have.)

I would rather do a batch at this time.
I have a text file; File1.txt  it has one Column with user names

User Name


I have anothe file; FIle2.txt it has 2 columns with user names and computer names.

User Name        Computer Name

YYYYY	            CM1
ZZZTT  	            CP2		
AAAA		    FR3	
LLLLL		    HR1
V77YSK		    SSSS57
DDDDD		    KERT210
U65TWQ		    OLI325
BBBB		    WSY56
JJ5142		    B9OHG

Open in new window

**As you notice some user names in File1 are in File2
I need a script that looks at each user name in File1 and search in File2 to see which computer name is assigned to.

So, the script needs to create File3.txt wich should look  similar to this:

User Name     Computer Name

Open in new window

Thank you
I have word document with text on it that looks similar to the excerpt  below:

 Mal, Glo <>; Lar, Mar V <>; Wil, Ly A <>; Wil, Ste <>; Nea, Mar<>; Har, Kim S <>

I need a script that goes through the document and retrieve only, the first part of the email.
for instance, for this : Mal, Glo <>
the script will retrieve only Gmaldonado and export it to a text file

the text file will look like:
Total new at my mysql and i need a batch/cmd to make a backup/dump of a schema name:poviseposdb and zip the file
It would be perfect to have a folder with date and time and it would be total perfect if there also will be a batch to restore the schema
Using a dutch windows 10 and preferred 7-zip

Thanks Danny
I'm using XCOPY to copy files from one directory to another.

When I manually run the batch job, it is asking me for permission to overwrite file in the target directory. It also asks me to type Y for the initial copy too.

I eventually want to schedule these jobs to run automatically, and I don't want them pause at waiting for a response.

How can I force the job to just copy or overwrite without asking for a Y or YES?

This is what I tried already:

xcopy  "C:\Bill Trust\108\Export Files\*.*" "C:\Bill Trust\108\BillTrust Archive" /s /e /R
We are testing windows 10 (Enterprise).  

We are finding that some parts of our login scripts (specifically registry hacks and copying files to the root of C, and likely others) fail (or prompt you) during the execution of the login script.

Tried changing the User Account Control Setting (Control Panel |  User Accounts)  to Never Notify which helped a bit but still encountered issues.

Changed the registry entry EnableLUA to 0 which resolved the login script issues however, the Edge browser and W10 audio player (and probably other native W10 apps) fail with the error "This app can't open.  Microsoft Edge can't be opened using the built in Administrator account. Sign in with a different account and try again.

Googled that error and apparently this is by design.

What are the best practices in a corporate domain environment to get around this limitation?  

What I am trying to do.
1) look at E folder location and see if there are any files (not folders, just files).
2) if there are files, stop.
3) if there are NO files, MOVE from S the first 25 files, then stop.

Ok, two servers. Admin access to both.

Server A (WinSrv2012)
Mapped drive to S:\  <--remote server folder
Mapped drive to E:\location\sharedfolder\main-folder <-- in this format in case it means something...this is a drive on Server A

Server B
Shared folder mapped to S on server A

My script is as follows

echo "Moving batch - running..."
@echo off

set Source=S:\
set Target=E:\location\sharedfolder\main-folder
set MaxLimit=5

	echo "Checking..."
	for /F %%i in ('dir /b /a-d "%Target%\*.*"') do (
		echo "%Target% contain files - no action."
		goto endbatch
	echo "%Target% do not contain any files - Moving new files..."
	goto movefiles
	for /F "tokens=1,2 delims=:" %%f in ('dir /b /a-d "%source%\*"  ^| findstr /n "^" ') do (
	   if %%f leq %MaxLimit% (
		   move "%source%\%%g" "%target%"
	   ) else goto endbatch
	goto endbatch
	echo "Moving batch - ended"

Open in new window

After running the :movefiles part I get "The filename, directory name, or volume label sytax is incorrect."
Is this from the - in the file name?
Perhaps there is an easier way to perform what I am trying to do. Windows Task Scheduler will run this file every 3 minutes for the next 6 months.
I am needing to create a batch file that will look for a string at the end of a file name and then copy the file to another directory.

In the file name I am looking to match the string "(U) [!]" and then move that file to a directory. All of the files are .zip files that I need to analyze.

Example files format:
File Name One (U) [!].zip
File Name Two (U) [!].zip
File Name Three (J) [1].zip
File Name Four (U) [b1].zip

From the example file names I would end up with these files in a directory:

File Name One (U) [!].zip
File Name Two (U) [!].zip

I've found a few examples online that seem to do what I want to do, but I don't know how to manipulate the content to match my parameters above.  Any help is appreicated.  Thank you.
Hi how do i remove all files and folder from a dir
ms dos command or something

i need it to put it in a bat file for run as shedule
On a Server 2012 server I have created a task that I have scheduled to run every night.

This task runs a batch file.

When I created this task I received the message shown in the screen shot "This task requires that the user account specified has Log on as batch job rights."

How can I grant this Active Directory user account the Log on as batch job rights?"

Batch file task scheduler right
I am using Windows 2008R2. I would like to write a batch file that grabs the latest(date) text file created in the directory, and uploads it to a FTP site. I would then schedule the batch file to run at the end of business everyday.

So I would like to go to this directory "C:\Invoice\Invoicedata" and grab the newest file. Then I would like it be uploaded to a FTP site that requires username and password. Then I would like to schedule it to run at 6pm everyday.
Hello, I need to write a Windows batch file that executes a different command depending on the day of the week.

So, every Monday it will run a command, every Tuesday another and so on, cyclically.

What would be the best way to accomplish this?

Thanks for the help.
how do i transform this in a robocopy line

xcopy d:\  w:\  /s /a /C /D:02-03-2016

is any way to copy only the today files in robocopy format?
hi i got the below script from this link, i need to know how i can install sophos AV on a machine without admin rights? basically can someone edit this script for a logon user that i can use to install with admin rights please?

 REM --- Check for an existing installation of Sophos AutoUpdate on 32-bit (the 'Sophos AutoUpdate Service' process)
 IF EXIST "C:\Program Files\Sophos\AutoUpdate\ALsvc.exe" goto _End
 REM --- Check for an existing installation of Sophos AutoUpdate on 64-bit (the 'Sophos AutoUpdate Service' process)
 IF EXIST "C:\Program Files (x86)\Sophos\AutoUpdate\ALSVC.exe" goto _End
 REM --- Check for an existing installation of Sophos Anti-Virus on 2003/XP (the SAV adapter config file)
 IF EXIST "C:\Documents and Settings\All Users\Application Data\Sophos\Remote Management System\3\Agent\AdapterStorage\SAV\SAVAdapterConfig" goto _End
 REM --- Check for an existing installation of Sophos Anti-Virus on Vista+ (the SAV adapter config file)
 IF EXIST "C:\ProgramData\Sophos\Remote Management System\3\Agent\AdapterStorage\SAV\SAVAdapterConfig" goto _End
 REM --- Deploy to Windows 2000/XP/2003/Vista/Windows7/2008/2008-R2
 \\SERVER\SophosUpdate\CIDs\Sxxx\SAVSCFXP\Setup.exe -updp "\\SERVER\SophosUpdate\CIDs\Sxxx\SAVSCFXP" -user USER -pwd PWD -mng yes
 REM --- End of the script

Hello experts,
On a laptop with Windows 7 OS,     bit, I would like to switch from one wireless network to another, using a script or a very simple program, which could be run on demand.
The laptop will have 2 wireless networks available to it, and I need the ability for the user to switch swiftly from one wireless network to another.   For instance form WirelessNetwork1, to WirelessNetwork2, and or viceversa.

If 2 scripts are needed then that is fine, however I need to make it as easy as possible for the users to switch from one network to another.

Thanks in advance for your assistance.

I want  a script that will delete the content of users sub folders, after 7 days, on a windows 2012 server.It will need to go through the list of users and delete any content older that 7 days in the sub folders. The list is based on the main folder name.

eg     main user   folder   bcotton
         sub folders              bcotton-a1

This is the one I have below, but the problem is that when I run it it is also deleting new folders in the sub account folders, less that 7 days old.

@echo off
set UserList=H:\users.txt
set topLevel=H:\ftpusers\ftp_users
for /f "delims=" %%u in ('type "%UserList%"') do (
      cd /D "%topLevel%\%%~u"
      FOR /D %%a IN (*) DO (
            forfiles /P "%topLevel%\%%~u\%%a" /S /M *.* /D -7 /C "cmd /C  del @PATH"
            cd /D "%topLevel%\%%~u\%%a"
            for /f "delims=" %%i in ('dir /s /b /ad ^| sort /r') do  rd "%%i">NUL

How do i alter to have it only look at files in the sub folders older than a week and not delete any new folders in the users subfolders.

Windows Batch





Batch files are text files containing a script of commands that are executed by the command interpreter on DOS, OS/2 and Windows systems. Most commonly, they are used to perform a series of functions that are repeated -- copying a set of files created daily with one step, for example.