Windows Batch

11K

Solutions

11K

Contributors

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 am looking for two batches that
1-delete /f based on a csv file.
2-rmdir /q /s based on a csv file.

-Full path of files to delete and remove directory will be reported in column a
-Two different batches or CMD and CSV files one for rmdir.csv and the other del.csv.

Logs files should be generated in order to check what has been removed.
Rmdir just remove reported folder and not parent folder.
/S option should be set up to remove subdirectories of reported folders.
 If you have questions please contact me.
0
Cloud Class® Course: CompTIA Cloud+
LVL 12
Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

Hello Experts,
I have a Root folders which contains multiple subfolders: Subfolder1, Subfolder2 etc.. Every Subfolder contains files or subfolders. I am looking for a vbscript or a batch file in order to drill down Root Folder and move the various files into a Destination Folder.
-Drill down process should check every subfolder of Root folder .
-Files can be located in Subfolders but also within subfolders of subfolders.
Thank you very much for your help.
If you have questions, please contact me.
0
Im trying to get a command so that files that are more than 30 days old are deleted.

in X:\BTPDOWNLOADS  and X:\CHILTERNDOWNLOADS  I have subfolders and what im trying to do is run a task every day to check if folder has been in there 30 days with the day I input being day 1 and if so delete it.

I.E I put a subfolder in to folder  X:\CHILTERNDOWNLOADS  on 1st January and I need it to auto delete on 30th  January or lets say I put it in on 14th April I need it to delete 13th May  and so on.

Any Ideas.
0
I need to run a batch script with elevated permissions.

I know that I can either right click and select run as administrator or Go to the properties of a shortcut of the script and select run as administrator.

Does anyone know of a way to automatically have this option selected instead of having to manually select it, other than using the runas command from the command line?

PS, yes I know this is probably not possible but I thought I would ask.

run as admin
0
I have a problem I tried to use psexec to run a .exe in a remote computer (same network) but is not working can somebody help me with this here is my script


C:\>psexec \\Computer2 -u root\administrator -p ******** "C:\Program Files\labprogram\lab\bb.exe plan -r JGnotorio"


the error is The System cannot find the file specified

but that's the correct path of the program

If I try local in Computer2 is working fine

any suggestion?
0
Hello Experts,

I have some unwanted files which start with the following prefix: "Test_Import".
Example :"Test_Import_20170804.csv", "Test_Import_201740804.log" in multiple folders located in my root folder C:\Data.
I am looking for a vbscript or a batch procedure in order to remove those files.

Additional information
In the script I should be able  report:
-RootFolder: In which are located the unwanted files to delete. The procedure should be applied recursively as they can be files in sub-levels folders.
-Prefix: In that case "Test_Import" but if I want to re-use the procedure I should be able to modify accordingly
-File extention. In that case the files have "csv" and "log" extension. If possible it would be great to report extentions.
Example: ExtentionFiles:"csv";"log" (Remove csv and log file which contains the prefix "Test_Import")
                 ExtentionFiles: "" (Remove all files not matter the extention)
-Add a log files generated in the same folder script in order to list the files removed and their locations


If you have questions, please contact me.
Thank you very much for your help.
1
I am trying to make a windows batch or vbs or powershell that will search a file and find a line of data and if found, export the whole line to another file.  Some values may change, but I still need the whole line exported.  

Example:  

file to be search contains a line like this...
"Server loaded 5 tickets..."  or "Server loaded 6 tickets..." (the number can change)

then output this whole line of data (regardless of the number value) to another file called "tickets.txt"

Is there any way to do this?
0
Hello experts,

I share xls files in a share folder. Users can copy and modify those shared files.
I would like to track:
-Who open and copy-paste locally those files.

Should I use a macro & vbscript & batch file for this?

Thank you very much for your help.
0
I had this question after viewing batch findtext match 2 criteria.
i am still playing with the above, however now i am having an issue while searching a csv i need to look for "DS" & "DSA" including the ", is there a way to accomplish this using findstr
perhaps with a double "
/c:"""ds"""

Open in new window

0
I need to use Robocopy to compare differences between source and destination directories located on two different file servers. I also need to output this to a log file. How can this be done in a batch do you have an example UNC \\fileserver1\e$ \\fileserver2\e$ and fileserver1 e drive and fileserver2 e drive etc?
0
Cloud Class® Course: Microsoft Azure 2017
LVL 12
Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

People,

Based on the builtin PowerShell command
Resolve-DnsName -Name bing.com -Type NS -DnsOnl

Open in new window


I need some help in fixing or modifying my PowerShell script below to perform:

1. Get the public IP address of the domain names in the .TXT file (or .CSV)
2. Get the DNS server responsible for the domain in the input .TXT file
3. Export the list as .CSV like below:

DomainName, PublicIP, DNS Server (NameHost)
www.domain1.com, 134.13.123.22, NS1.domain1.com
www.domain1.com, 134.13.123.25, NS2.domain1.com
www.domain2.com, 201.52.234.1, NS1.domain2.com

$InputFile = 'C:\Domainlist.txt'
$addresses = get-content $InputFile
$reader = New-Object IO.StreamReader $InputFile
while ($reader.ReadLine() -ne $null) { $TotalRecords++ }
write-host    ""
write-Host "Resolving DNS on each domain..."
foreach ($address in $addresses)
{
	## Progress bar
	$i++
	$percentdone = (($i / $TotalRecords) * 100)
	$percentdonerounded = "{0:N0}" -f $percentdone
	Write-Progress -Activity "Performing DNS Resolve" -CurrentOperation "Working on domain: $address (IP $i of $TotalRecords)" -Status "$percentdonerounded% complete" -PercentComplete $percentdone
	## End progress bar
	try
	{
		Resolve-DnsName -Name $address -Type NS -DnsOnly
	}
	catch
	{
		Write-host "$address was not found. $_" -ForegroundColor Green
	}
}
write-host    ""
write-Host "Pinging each address..."
foreach ($address in $addresses)
{
	## Progress bar
	$j++
	$percentdone2 = (($j / $TotalRecords) * 100)
	

Open in new window

0
I try to use a dos batch script which I found in internet but it does not work. I have only adjusted the two “set  scriptname= …” and “set prodir=…”
---
The script look like this:
@echo off
 
REM set to location of this script
REM +++ set scriptname=<XXX>\purgeall.bat +++
set scriptname="C:\Users\top\Desktop\purgeall.bat"
REM set to pro/engineer loadpoint
REM +++ set prodir=<Pro/ENGINEER Load Point> +++
set prodir="C:\Program Files\PTC\Creo 4.0\M030\Parametric"
if "%1" == "purge" goto p2
cls
call %prodir%\bin\purge.bat
echo.
FOR /D /R "D:\PTC\Gast\Test_1" %%a IN (*.*) DO call %scriptname% purge "%%a"
 
:p2
cd %2
echo Purging %2.
echo.
call %prodir%\bin\purge.bat
---

I get this error message in windows 7 64 bits ultimate in a cmd window when I start the batch program in that cmd window:
The command “C:\Program” is either wrong written or it is not possible to find
(I have translated the error message from German to English)
What have I done wrong to use this script?
The sub batch program purge.bat works if I use it direct in the cmd window.
0
I need to execute a Route Delete command in a batch file at startup so that it runs automatically.

Windows 7 computer.

This requires administrator privileges.

How can I accomplish this?

Thanks.

Tom
0
trying to make an exception to a batch file to stop the RDP from running on all TR-2016 which are Virtual machines but my script is failing to miss these out

@echo off

IF "%COMPUTERNAME%" == "TR-2016" GOTO END

if '%username%' == 'Train01' goto TR-2016-01
if '%username%' == 'Train02' goto TR-2016-02
if '%username%' == 'Train03' goto TR-2016-03
if '%username%' == 'Train04' goto TR-2016-04
if '%username%' == 'Train05' goto TR-2016-05
if '%username%' == 'Train06' goto TR-2016-06
if '%username%' == 'Train07' goto TR-2016-07
if '%username%' == 'Train08' goto TR-2016-08
if '%username%' == 'Train09' goto TR-2016-09
if '%username%' == 'Train10' goto TR-2016-10
if '%username%' == 'Train11' goto TR-2016-11
if '%username%' == 'Train12' goto TR-2016-12
if '%username%' == 'Train13' goto TR-2016-13
if '%username%' == 'Train14' goto TR-2016-14

goto end

:TR-2016-01
\\fs01\tws$\icons\Train\TR-2016-01.rdp
goto end

:TR-2016-02
\\fs01\tws$\icons\Train\TR-2016-02.rdp
goto end

:TR-2016-03
\\fs01\tws$\icons\Train\TR-2016-03.rdp
goto end

:TR-2016-04
\\fs01\tws$\icons\Train\TR-2016-04.rdp
goto end

:TR-2016-05
\\fs01\tws$\icons\Train\TR-2016-05.rdp
goto end

:TR-2016-06
\\fs01\tws$\icons\Train\TR-2016-06.rdp
goto end

:TR-2016-07
\\fs01\tws$\icons\Train\TR-2016-07.rdp
goto end

:TR-2016-08
\\fs01\tws$\icons\Train\TR-2016-08.rdp
goto end

:TR-2016-09
\\fs01\tws$\icons\Train\TR-2016-09.rdp
goto end

:TR-2016-10
0
Hello Experts,

Using this batch how to print %sum1% in words along with numbers

@echo off
:Loop
echo Enter a number:
set /p num1=  
set /a sum1="num1 * 100000"
echo The total is %sum1%
goto :Loop
0
I need a batch (ie .bat or .cmd) logon script that will check if the hostname is one of the 20
& if so, then only execute a series of commands on the PC.  The pseudo code will be like:

if %computername%="host1"  or ... or %computername%="host20"
then
   (
    command 1
    command 2
   )

Basically I need to get the syntax right
0
Hello,

done a search and haven't found anything exactly like what I'd like to do.

We have a single domain with users in multiple locations. Each main location has its own file server and users map their home drive based on their location. We've had issues with home drives not mapping in remote locations that do not have a local server. We believe it may be timing out, that issue is being looked into.

Rather than have our IT staff manually map the drives, I'd like to do a small script we could place on their desktop that allows users to put their primary location, which would then map their home drive to the correct server.  Something like this.

Please select your primary location:
0 = HQ
1= Region 1
2= Region 2
3 = Region 3
4 = Region 4

Based on their answer I assume it would then run a command

HQ
Net Use K:\\hqserver\vol\%username%

Reg 1
Net Use K:\\r1server\vol\%username%

Reg 2
Net Use K:\\r2server\vol\%username%

Reg 3
Net Use K:\\r3server\vol\%username%

Reg 4
Net Use K:\\r4server\vol\%username%

I've tried writing a few, but scripting is definitely not a strong suit. I'm sure it would take a talented scripter about 2 minutes.

TIA
0
Running a batch file from excel

The code in excel is:

set arg1 %1

if [%1] equ [] set arg1=%cd:~0,1%

echo "Test" %arg1%

echo %arg1%:\ZZZ\ZIP-BAT\source-zip.txt

dir e:\ZZZ\Zip-Bak\DayBkup\hm18*.zip>%arg1%:\ZZZ\ZIP-BAT\source-zip.txt

dir %arg1%:\ZZZ\Zip-Bak\DayBkup\hm*.zip>%arg1%:\ZZZ\ZIP-BAT\dest-zip.txt

The Dos batch file content is

set arg1 %1

if [%1] equ [] set arg1=%cd:~0,1%

echo "Test" %arg1%

echo %arg1%:\ZZZ\ZIP-BAT\source-zip.txt

dir e:\ZZZ\Zip-Bak\DayBkup\hm18*.zip>%arg1%:\ZZZ\ZIP-BAT\source-zip.txt

dir %arg1%:\ZZZ\Zip-Bak\DayBkup\hm*.zip>%arg1%:\ZZZ\ZIP-BAT\dest-zip.txt


I get an error Environment variable not defined (see attached screen shot)

Need help

Thanks
Dos-Batch.JPG
0
I need to connect to FTP server through Command Prompt.

When I am trying to connect to it, it says Connection Timed Out.

D:\>ftp
ftp> open
To xyz.test.com
ftp: connect :Connection timed out
ftp>

What must be the reason behind it? Please help

I can connect to it through Filezilla.
0
Get expert help—faster!
LVL 12
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

I created the following script to create a fake reg key, if the key isn't present - install software. If the key is there, fall out and end the execution.

The script works just fine. My challenge is when it executes, i get the dialog box pop up - which i do NOT want to be displayed.

Again, the script works fine - but how can i edit the script so i DO NOT receive the notification dialog box as shown in the attachment? (prefer to leave it as a .cmd script if possible). Thanks!

@echo off
rem queries if fake regkey is present
reg query "HKEY_LOCAL_MACHINE\SOFTWARE\DotNetCheck"
if %errorlevel%==1 (goto Install) else (goto End)
REM If errorlevel returns value 1, key is not present and prgm will create key and install .net3.5

:Install
REG ADD HKLM\SOFTWARE\DotNetCheck
dism /online /quiet /enable-feature /featurename:NetFx3 /All /Source:\\ds-dfs01\sxs /LimitAccess

:End
DialogBoxWishToGoAway.png
0
How do I convert this batch file into a exe or powershell script.
0
I have a test_file.txt

------------------------------------------test_file.txt------------------------------------------------
3
ID | Name | Gender
x1 | A | M
x2 | B | F
x3 | C | M
------------------------------------------------------------------------------------------


3 is our record count.

I need to write a batch script where I have to store the record count value in one variable(X), need to store the data values ( 3 row) in to another variable (Y)
and have to compare both the variables if X == Y then execute a SQL job (ABC) and if they are not equal fail the script raising an ERROR.

Please help folks as I think this is the only forum which can help me solving my problem.
0
Usage will be a daily task to copy only new or modified files into a new folder name with current date.
robocopy \\Srv1\Data\John \\Srv2\Bkup\John\20180507 /maxage:1 /s
0
Try to use the following command to backup a folder. However, it always stay in the attached screen. Any idea ?


robocopy.exe Z:\" D:\ARCH17 /copyall /E /Z /NP /nfl /ndl /r:0 /tee /MIR /XD "@Recycle" "@Recently-Snapshot" /xf "Thumbs.db"  /Log+:C:\MyBackup\robocopy.log

Thx
screen.png
1
Split 1 text file into multiple textfiles based on Row starts with CC and rename the files into different file name.

Rows AA, BB are headers need to be added to the file after the split. Split based on Row CC.

I don't know what is the best way to do this. I am lost.

Is this possible?

See attached:
Original File to be split: Test_05022018.txt

Results should be like this: See attachement.
Test000000001_05022018.txt
Test000000002_05022018.txt
Test000000003_05022018.txt

See attache excel file for more info.


Please help.

Thank you again.
Split_To_Multiple_Texts.xlsx
Test000000001_05022018.txt
Test000000002_05022018.txt
Test0000000003_05022018.txt
0

Windows Batch

11K

Solutions

11K

Contributors

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.