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

Hello experts,

I have a root folder which contains multiple suboflders.
I was wondering how to set up del command in order to delete the various folders located in the various subfolders without reporting one by one subfolders.

normally if I do

cd C:\RootFolder
del* /q is not working.

Which options should I added.

Thank you very much for your help.
Get your problem seen by more experts
LVL 12
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

In a batch file I am using a variable to get the files names with extension abc.bak ( when I am passing the variable to a executable I wanto trim .abc and pass only xyz.bak
 I am using the below command but getting it is now working.  I should only replace this at -E

@echo off
for /r %%i in (*abc.bak) do xyz.exe -F %%i -E %%I
How do I use Task Scheduler in Windows to execute a shell script file (.sh extension)?
If cannot use Task Scheduler, how to create a crobjob that execute a shell script file (.sh extension) in Windows?
Hi guys ,
i need to create a batch file.
i got a file in c\windows\syswow64\xxx.ocx

i need to run this command at the computer startup each time.
regsvr32 xxx.ocx       - so it registers in registry

if i can create a batch file, i can make it to run at startup.  but i want to know. how to create a batchfile to make this command run "regsvr32 xxx.ocx" and xxx.ocx is in " c\windows\syswow64\xxx.ocx"

any help would be great.
Hi Experts,
How to create multipal users along with password & assign to remote desktop group in Windows server 2008 & 2012 from batch file ?
I am attempting to write an automated uninstall string, same app, multiple versions. I would have preferred to do this via PowerShell but apparently their servers are so old only some of them support it. So I have found a command line way to find the uninstall strings from the registry, but I am not sure how to pass the string to an execute inside of a batch.

reg query "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall" /s /f "OpenSSL" | findstr /B ".*UninstallString"
reg query "HKLM\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall" /s /f "OpenSSL" | findstr /B ".*UninstallString"
I need a batch file to install a Window update on a remote machine. I need to have it check if its online, if its not exit out with an error, if its online look for C:\Temp, if its not there create it. Then copy over the file to C:\Temp and run the file using psexec.exe.

The reason why we are doing it this way is because SCCM is not working for us and NO we cannot use other deployment software. I am however allowed to use a batch file or script.
Hello, I need to disable batch file execution in RDP (Windows 2012 r2) session for a regular user. Administrators should be able to run batch scripts. If GPO "Prevent access to the command prompt" is enabled and "Disable the command prompt script processing also?" set to "Yes" then batch files cannot be executed but login script cannot run as well.

Also, GPO has a note:
"Note: Do not prevent the computer from running batch files
if the computer uses logon, logoff, startup, or shutdown
batch file scripts, or for users that use Remote Desktop Services."

If this option set to "No" then login script can be executed but command prompt can be opened by executing a batch file with following content:
@echo off
set /p cmd="%cd%> " 
goto loop  

thank you.
We run PSEXEC often to distribute software and icons.  I was wondering if there was a way or a script that I could run to check and make sure my Icon got installed?  These are for both windows 10 and windows 7
Hello experts,

I use the following command to create folder structure (subfolders) without files from one folder to another

Robocopy C:\Reference C:\FolderToApplyStructure /e /xp

Open in new window

The problem of this command is that it drill down the various folders to the last levels and I would like to omit drill down sub folder creation for specific folders.

The idea is to use the same command with a Flag DrillDownOff in which I report the name of the folder.

Example C:\Reference\Level1 contains multiple folders toto titi etc..

If DrillDownOff = “titi”

This means that subfolders of titi folder will not be created.
DrillDownOff should accept multiple folders name.
If reported folders in DrillDownOff exists in multiple locations it should be applied for all of them.

If you have questions, please contact me.
Cloud Class® Course: Amazon Web Services - Basic
LVL 12
Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

I have a huge folder (containing about 7 million file) that needs to be moved to a new file server (folder size : only 20G)
I started yesterday, a ROBOCOPY command with the /LOG switch.
The problem now is, i believe that the logging is making the operation very slow. (log size till now : 200M)
I would like to know now, if it is possible, by any means, to stop logging without interrupting the copy process.
Thank you in advance
When I run this statement, I get an error that says "%%G was unexpected at this time":
for /F "tokens=2 delims==" %%G in ('WMIC /NODE:"myserver" Service WHERE "Name = 'myservice'" GET State/value') do set CURSVCSTATE=%%G

But, when I run just the WMIC statement, it works fine:
WMIC /NODE:"myserver" Service WHERE "Name = 'myservice'" GET State/value

I'm pretty sure it has to do with the single quote terminating the WMIC command to early, but I can't figure out how to fix it!
I have a windows batch file with echo off that gets user input using the SET /P statement like this:
SET /P UserAnswer=What is your answer?

I am calling this batch file with another batch file (CallerBatch.bat) using the "CALL" command and I'm using the > character to redirect the output to a file, like this:
CALL "MyBatch.bat" >MyOutput.txt

The problem is that when I run CallerBatch.bat, I never see the "What is your answer?" appear, even though the system is waiting for the user input.

How can I set it up so that this can happen?
if exist z:\
	If Exist Y:\
		If Exist X:\
			(net use w: /user:UserPassword)

			Copy %USERPROFILE%\Desktop\ w:


			Net use w: /Delete

			Else (net use x: /user:UserPassword)

			Copy %USERPROFILE%\Desktop\ x:


			Net use x: /Delete


	Else (net use y: /user:UserPassword)

	Copy %USERPROFILE%\Desktop\ y:

	Net use y: /Delete
else (net use Z: /user:UserPassword)

Open in new window

So what i'm trying  to do is check if drive mappings exist, if they do move to the next drive mapping and check that. Etc etc.

Can't seem to get it to work quite right, Batch scripting isn't my strong point unfortunately.

Hello experts,

i use the following batch reported at:

in order to list files and folders into a csv:
@echo off
setlocal EnableDelayedExpansion

set BaseDir=c:\temp
set ListFile=list.csv

if exist "%ListFile%" del "%ListFile%"

echo "File_Folder_Path";"Type";"File_Folder_Size">>"%ListFile%"

for /f "tokens=*" %%A in ('dir /s /b "%BaseDir%\*.*"') do (
    for %%B in ("%%~A") do (
        if exist "%%~A\" (set FileType=D) else (set FileType=F)
        echo "%%~A";"!FileType!";%%~zB>>"%ListFile%"

Open in new window

By default the procedure drill down the various files and folders.
I would like to add a flag drill down option. If Yes drill down else just list files and folders at basedir level.

If you have questions, please contact me.
I am trying to create a task (in task scheduler) to execute a vbscript file. Task Scheduler successfully completed but the vbs script is not creating task file. But when I manually run the .vbs task file is create.

@echo off
cscript //nologo c:\xxxx.vbs

Task Scheduler successfully completed task "\xxxx" , instance
"{355a1874-adfa-499d-bee7-25e3d4e2b7db}" , action
 "C:\Windows\System32\cscript.exe" with return code 0.
Need some help with a DOS batch file or powershell script, either will do, Have (2) csv's and need the column of file2.csv appended with file1.csv to create file3.csv, Both source files have same row count. Need to append headers not required.

brown, blue, 123, yellow
purple, black, 456, magenta
pink, teal, 789, grey


brown, blue, 123, yellow, alpha
purple, black, 456, magenta, bravo
pink, teal, 789, grey, charlie

So I am in the middle of changing a scheduled tasks account that it runs under as the current ones password is changed monthly.
I have added the account to the same groups for permissions as the previous account.

The basics of the script are:
Connect to FTP
Download files
Rename files
Move files
Archive files

Now when i run a test on the script it is for some reason it was unable to see the txt file that connects to the FTP account, i have to edit the command to point the script to the full path location "C:\tempfiles\ftpscript.txt" instead of it previously using "\ftpscript.txt", then it is also downloading the files into my documents and not the directory that it was downloading to before "C:\tempfiles"

It is as if the cmd prompt looks to different locations when run under those different accounts? I am not sure why it is now downloading in that location when it ran fine before. I think the only difference between the 2 accounts are that the previous account was the built in domain admin account and this is a new account we created which is also a domain admin account.

Script below:

:: Download all files via WINSCP
"C:\Program Files (x86)\WinSCP\" /script=ftpscript.txt

:: Rename files
cd: "c:\tempfiles"
ren p3de* "temp file1"
ren p3tr* "temp file2"

:: Move files

::Archive files
MOVE "C:\Tempfiles\*.* "C:\tempfiles\archive"

Now so far i have amended the download command to …
How to call Powershell script ps1 file by installshiled 2009.

I have file ps1 script file and I need to call or execute that file by installer.By the cmd  code I execute that file by Launchapp method of installer.Please see the image Code image.

But i get the error.Please see the image  Error.
Cloud Class® Course: C++ 11 Fundamentals
LVL 12
Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

I have the following script and its not copying from ="S:\CCTV Downloads\Chiltern Downloads"  to "S:\CCTV Downloads\safety dept"

Everything else OK.

Any ideas?

set DBTP="\\crcl.local\ApplicationData\BTPCCTVDownloads"
set DCRCL="S:\CCTV Downloads\Chiltern Downloads"
set DSAFE="S:\CCTV Downloads\safety dept"
xcopy %SBTP% %DBTP% /e /d
xcopy %SCRCL% %DCRCL% /e /d
xcopy %DCRCL% %DSAFE% /e /d"
for /d %%A in ("%SBTP%\*.*") do rd /s /q "%%~A"
del /q "%SBTP%\*.*"
for /d %%A in ("%SCRCL%\*.*") do rd /s /q "%%~A"
del /q "%SCRCL%\*.*"

Open in new window

Trying to get a complete list of installed programs.
Using this command gives me partial list: wmic /output:"C:\software.csv" product get "Description","InstallDate","Name","Vendor","Version"
Using this gives another partial list: reg query HKLM\Software\Microsoft\Windows\CurrentVersion\Uninstall /s | find "DisplayName" > C:\InstallList.txt

Also "reg query" won't seem to get all the values desired as in the "wmic" command.
Im totally new to robocopy and looked on the internet and come up with this command.
Could someone possibly just check for me.

Im trying to move from


then delete all data from C:\DOWNLOADSA and C:\DOWNLOADS just leaving the folders

Script below


Open in new window

How to create a batch file to install an .exe file with administrative privilages?
We are currently using a batch file that runs a 'mkdir' using a pre-defined variable and then calls another batch file to run a backup task, to supplement our existing tape backup for a short period of time.

setlocal enableextensions
set name=%DATE:/=_%
mkdir G:\Backup\%name%
call C:\FFSBackup.bat

Open in new window

This produces folder names in the format 20_06_2018

I would like to be able to have another scheduled task to delete historical directories - the above runs daily (Mon-Fri) through a scheduled task and I would like to be able to remove directories that are, for example, older than 5 days to manage space on the destination disk - a USB drive. Is there any way I can use the above date variable to achieve this?
Hello experts,

I am looking for a BAT files in order to list in a List.csv files, files, folders path and size.
First column: Path of File or Folder
Second column: report if the line reported in first column is a FILE or a FOLDER
Third column: size related to FILE or FOLDER

In the BAT file I should report the folder where are located the various files and folders to report in List.csv
BAT files should drill down the various subfolders.

If you have questions, please contact me.

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.