Windows Batch

12K

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

I am writing a cmd file to utilize robocopy as an automated backup. I want to create a new log every time it runs that is date stamped as part of the log name. I am using the script below. The log was named Tue09172019-8212265Home. However I want the format to be yyyymmdd-hhmm so in this case 20190917-0821Home.


set tdate=%date: =%
set tdate=%tdate:/=%
set ttime=%time::=%
set ttime=%ttime:.=%
set ttime=%ttime: =%


Robocopy G:\Home F:\Home /e /b /xo /copyall /dcopy:DAT /mt /LOG:F:Logs\%tdate%-%ttime%Home.log /NFL /NDL
0
Become a Certified Penetration Testing Engineer
LVL 13
Become a Certified Penetration Testing Engineer

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

Hello experts,
I am looking for a script to replace single space or multiple spaces at files and folders located in a root folder by "-" characters
The idea is to have as variables:
      The character that is going to replace single or multiple spaces
      Drill down mode flag
Powershell & VB Script & Windows Batch approaches are more than welcome.
Thank you for your help.
0
I'm trying to create a batch file that will add the current date to a file. I found this online - but it only works when you enter it directly on the command line
for /f "tokens=1-5 delims=/ " %d in ("%date%") do rename "filename.pdf" filename_%g%e%f.pdf

If its in a bat file I receive this message
dategf.pdf was unexpected at this time.
screen shot of running commands
I'm looking for a solution and I'm not tied to this one if you have a better option.

Thank you!
0
Hello experts,
I am looking for a script that covers the following requirement:
Find duplicate files in a folder:
Keep newest file remove oldest file.
Powershell & Windows batch approaches are more than welcome.
Thank you f or your help.
0
I wud like to prevent non-admin users from amending the following
2 registry values:

Computer\HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings
a) ProxyEnable
b) ProxyServer

Seen the following link but still can't grasp it, so will need the
exact setacl command to be applied on the registry:
https://helgeklein.com/setacl/documentation/command-line-version-setacl-exe/

Another EE expert has given me the PS method below
but we don't have access to PS & would like to do it in
batch scripts/commands.

1:$acl = Get-Acl "HKLM:\SOFTWARE\Example"
2:$person = [System.Security.Principal.NTAccount]"BuiltIn\Users"          
3:$access = [System.Security.AccessControl.RegistryRights]"FullControl"
4:$inheritance = [System.Security.AccessControl.InheritanceFlags]"ContainerInherit,ObjectInherit"
5:$propagation = [System.Security.AccessControl.PropagationFlags]"None"
6:$type = [System.Security.AccessControl.AccessControlType]"Allow"
7:$rule = New-Object System.Security.AccessControl.RegistryAccessRule($person,$access,$inheritance,$propagation,$type)
8:$acl.AddAccessRule($rule)
9:$acl |Set-Acl
0
I have 2 registry values that I use regedit to update & delete respectively.
What's the command (in Command prompt) to make the same change?

Under
Computer\HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings

a) ProxyEnable : would like to change it's value from 1 to 0
b) ProxyServer : to remove any values in it (ie make it nul value)
0
I am trying to create a Robocopy script that will copy files from one location to another location and purge the source files based on the timestamp. The script runs every hour at :00 and it copies the files to another location but, I want it to only delete the source files that are older than 15 minutes prior to the top of the hour. For example, the script runs at 11pm and I want it to only delete files older than 10:45pm. This is what I have currently in my script but, I don't know what switch(es) to use to do the file delete based on timestamp.

robocopy "\\10.11.20.10\Share\CX" "D:\FC_Import\CXM" /S /E /SEC /MOV /COPYALL /V /NP /LOG+:"d:\Robocopy.txt" /R:3 /W:5
0
HI,

I'm looking for help writing a batch file.

I want to use it as part of a start up GPO,

Install an MSI silently, if the folder already exists skip the install, report the results to a temp.log.

Can someone please assist - thanks
1
Hello experts,

I am looking for a windows batch (robocopy) to copy files from strSourceFolder to strDestinationFolder with specific extension and with a creation date equals to 201900801.
If you have questions, please contact me.
0
Hello experts,

I have the following procedure which allows me to append log files on specific folder:
@echo off
setlocal

set BaseDir=B:\EE\EE29154094\Files
set MergeFile=B:\EE\EE29154094\merge.csv

echo.filename;datemodified;content>"%MergeFile%"

for %%A in ("%BaseDir%\*.*") do (
    if /i NOT "%%~A" == "%MergeFile%" (
        for /f "tokens=*" %%B in ('type "%%~A"') do (
            echo.%%~nxA;%%~tA;%%B>>"%MergeFile%"
        )
    )
)

Open in new window


I would like to add the following requirements
-Be able to report a date stamp to append based on this date
Example:
DateStamp: 15
Append files newer or equal than 15 days.
If you have questions, please contact me.
0
C++ 11 Fundamentals
LVL 13
C++ 11 Fundamentals

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

Hi,
I want to run a windows batch file on a remote computer using PowerShell. I have tried with this following command but didn't work.

Invoke-Command -ComputerName "ccccccc" -credential domain\xxxx -ErrorAction Stop -ScriptBlock {Invoke-Expression -Command:"cmd.exe /E 'E:\_deployment\ServicePack\Install_ServicePack.bat'"}

Please help
0
I have the following batch file now I want to add STEP 1 STEP 2 if STEP 1 FAILED then goto next step and send email or generate output in txt

powershell.exe -executionpolicy bypass -file J:\Backup\EnableTCP-IP_Named_Pipes.ps1
powershell.exe -executionpolicy bypass -file J:\Backup\Restart-SQL_Server.ps1
if errorlevel 1 echo Unsuccessful > J:\Backup\result.txt
if errorlevel 0 echo command executed successfully > J:\Backup\result.txt

Thanks
0
Hi Experts,
I am looking for a program that will list all PC names, browser names and versions within the network.
Would prefer it to be done either as a DOS command, batch file or VBA.
Thanks
0
Hello experts,
I have the following script which allows me to create monthly folders and move files.

 
@echo off
setlocal EnableDelayedExpansion


rem Get current date
for /f "tokens=2 delims==" %%G in ('wmic os get localdatetime /value') do set datetime=%%G

rem get year, month, day variables
set Year=%datetime:~0,4%
set Month=%datetime:~4,2%
set Day=%datetime:~6,2%


rem Define file and folder locations
set BaseDir=%cd%
set InputFolder=D:\
set LogFolder=D:\HISTO\%Year%\%Year%-%Month%


rem Make sure needed folders and files exist
if not exist %LogFolder% md %LogFolder%
if not exist %InputFolder% exit /b
if not exist "%InputFolder%\*.csv" exit /b

rem Copy csv files to log folder
xcopy "%InputFolder%\*.csv" %LogFolder% /Y

Open in new window

I would like to take it as a reference to add the following requirements:

Check modified date of files to move. Move files older than 2 days on it respective monthly folder.
Example :
Þ      Toto.csv has a modified date equal to 2019/07/13 it should be moved to 07-2019 folder.
Þ      Titi.csv has a modified equal to 2019/08/12 it should not be moved as it hasn’t a modified date older than 2 days.
If you have questions, please contact me.
Thank you for your help.
0
Hi Experts,

How can I modify this DOS command to only look at files created after a certain date?

Thanks
0
Hello experts,
I have the following batch which allows me to count files on specific folder:
@echo off
setlocal enableextensions
set count=0
for %%x in ("C:\Temp") do set /a count+=1
echo Number of csv files: %count%
endlocal
pause

Open in new window


I was wondering how to put:
-/d option to specify files with a date modified older than 30 days
-/s option to proceed recursively

If you have questions, please contact me.
Thank you for your help.
0
I have a subtitle file (srt format) file like this :


1
00:00:00,701 --> 00:00:20,033
ffdfdfddfdf
2
00:00:20,701 --> 00:00:30,033
fdfddfdgdgdgdg
3
00:00:32,000 --> 00:00:38,074
hhhghghggh
4
00:00:42,701 --> 00:00:45,033
vvvffffgdfg

those are only the first 4 lines,but it is very long. What I want to do is to write a batch script that does the following things :

1) it removes all the sentences that are under the timings. In this particular case are : "ffdfdfddfdf" ; "fdfddfdgdgdgdg" ; "hhhghghggh" ; "vvvffffgdfg" ;

2) it changes the sentences that I mentioned above with the number with which each subtitle starts. In this particular case with : "1" ; "2" ; "3" ; "4" ;

So,at the end it should do something like this :


1
00:00:00,701 --> 00:00:20,033
1
2
00:00:20,701 --> 00:00:30,033
2
3
00:00:32,000 --> 00:00:38,074
3
4
00:00:42,701 --> 00:00:45,033
4

that's all. Really I can't do that manually because it takes a lot of time. And I don't know enough how the batch scripting works. I don't know any other language at all. I'm sorry but I can't give you a small piece of code to fix. I hope to find someone that can understand my situation and that can write the code for me. very thanks.
0
The request is fairly simple :
I have a script/batch that some of my friends would like to use (so the request can not be implemented by group policy).
Let's call my script "Batch_a.bat".
"Batch_a.bat" is to be run at user login   (it checks something).
I want another script/batch that will copy "Batch_a.bat" to "C:\zmau" and then add a shortcut into Startup or added to registry under "HKCU\Microsoft\windows\current version\run key"
I would be happy to get both options.


Thanks
zmau
0
Hello experts,
I have a bunch of log files to analyse. They are located in the same folder.
They don't contain common header and they can contain multiple lines.
I would like to append them into a single CSV file with it file name.
The idea is to have the following:
File name; contain; Date modified (related to file)
If a file contains multiple lines. File name should be dupplicated.
Example:
File 1; line 1; Date modified
File 1; line2; Date modified
If possible have a header with the following:
File name; content; Date modified
If you have questions, please contact me.
0
OWASP: Forgery and Phishing
LVL 13
OWASP: Forgery and Phishing

Learn the techniques to avoid forgery and phishing attacks and the types of attacks an application or network may face.

Hello experts,

I have a root in which I have multiple folders and files.
I am looking for a procedure that allows me to:

1)Based on a config-csv-replacement in which I am going to report as of line one Current_Value;New_Value replace literally Current_Value by New_Value
2)Example: toto;tata. toto value should be replaced in all the files located in Root folder and subfolders
3)Log file should be generated to report files in which the replacement took place
4)config-csv-replacement should support multiple lines entries. If config-csv-replacement is complicated to set up, I am in to report Current_Value;New_Value lines in the script

If you have questions, please contact me.
Thank you for your help.
0
Running MySql version 5.7 on Windows 7 Pro.  I am learning MySql .
My goal is to put the MySql password into a file so I don’t have to put the plain text password into batch files I want to invoke .There is much I do not understand about the relationship between MySql and Windows permissions.

Before executing mysql_config_editor, I would manually navigate to the
cd “Program Files\Mysql\Mysql Server 5.7\bin    folder
   and then type             mysql
  I would get a prompt for password.  I enter the password and the MySql command prompt appears.

I read about mysql_config_editor.  So I typed:
  mysql_config-editor  set –user=root –password
  The   mysql_config-editor prompted me for a password .  I entered the password.

  Then I navigated to the bin folder as above.
  I typed          mysql and this time the mysql command prompt immediately appears, no prompt for password.
  The mysql 5.7 manual says the   mysql_config-editor  will create a file called mylogin.cnf  .  I have searched all the drives on my Windows 7 computer and cannot find this file.  Yes, I am logged in as administrator, I have full rights.

So I thought now, when I execute a Windows batch file,  I just need to enter the –user=root command in the batch file  and MySql will log in as user root without any need for me to provide a password.  And this works as long as I am logged in as administrator.

Questions:
Q1.)  I cannot find any file called mylogin.cnf .  I cannot find any file …
0
Hello experts,
I am trying to create copy 100 times specific file however I just got one file copied
for /l %A in (1,1,100) do copy /y ^
"C:\temp\file.txt" ^
"C:\temp\file.txt%A.txt

Open in new window

Could you please advice on this?
Thank you for your help.
0
Hello experts,
I have the following procedures reported at: https://www.experts-exchange.com/questions/29153639/
Batch approach
@echo off
setlocal

set BaseDir=B:\EE\EE29153505\Base
set DestLog=B:\EE\EE29153505\DestLog
set DestCsv=B:\EE\EE29153505\DestCsv

for /f "tokens=*" %%A in ('findstr /m /b /v /c:"0;" "%BaseDir%\*.log"') do (
    move "%BaseDir%\%%~nxA" "%DestLog%"
    move "%BaseDir%\%%~nA.csv" "%DestCsv%"
)

Open in new window


Powershell approach
$sourceFolder = 'C:\Temp\input'
$targetFolderLog = 'C:\Temp\output'
$targetFolderCsv = 'C:\Temp\output2'
Get-ChildItem -Path $sourceFolder -Filter *.log |
	Select-String -Pattern '^[^0]' -List |
	ForEach-Object {
		Move-Item -Path $_.Path -Destination $targetFolderLog
		Move-Item -Path $($_.Path -replace '\.log$', '.csv') -Destination $targetFolderCsv
	}

Open in new window

Which allows me to move log files and it csv equivalent to specific folder if at least one line of log file start with a value different that 0.
I would like to cover additional needs:
-Execute the procedure during 10 hours. As a result I need a WaitingTime of 10 hours (time that procedure will be active) and a LoopRecurrency variables of every 30 second (time that procedure need to check in reference folder)
-Copy (instead of moving) csv file to csv-error folder and log file to log-error
-Generate and append csv files and log files in listing Csv-error.csv & Log-error.csv files involved by the copy reported in previous step.
If you have questions, please contact me.
Thank you for your help.
1
I need to use the SOX utility to loop through and merge a bunch of audio files. I have 81 unique audio files and need to merge each one with an intro audio tag that is a single file. For instance, I have audio files File1.mp3-File81.mp3 and need to merge the intro audio file Intro. mp3 with each one. The intro.mp3 needs to be placed at the beginning so likely needs to be listed first in the sox command. I think the basic sox command is "sox -m file1.wav file2.wav output_file.wav".  All 81 unique audio files and the intro file are combined into a single folder. So I am looking for a batch statement to loop each one with sox. I also need the batch to rename the output file as EPR5007.mp3, sequencing each merged file in increments of 1, so EPR5008, EPR5009, etc.
0
Hello experts,

I would like to cover an additional need related to question https://www.experts-exchange.com/questions/29153505
Solution proposed move log files from input to output if one file contains at least one line which doesn't start with 0.

Powershell approach:

$sourceFolder = 'C:\Temp\input'
$targetFolder = 'C:\Temp\output'
Get-ChildItem -Path $sourceFolder -Filter *.log |
	Select-String -Pattern '^[^0]' -List |
	ForEach-Object {Move-Item -Path $_.Path -Destination $targetFolder}

Open in new window


Batch approach:
for /f "tokens=*" %%A in ('findstr /m /b /v /c:"0;" "C:\TEMP\BASEDIR\*.log"') do move "%%A" "C:\TEMP\DESTDIR"

Open in new window


Additional need:

In input folder I have .log file and also it .csv file equivalent example : ReqXXXX.log and ReqXXXX.csv,

I would like:
-move log file in output (as is)  
-move csv file equivalent into an output2 folder

Assumption:
-Every log file has it csv equivalent.

If you have questions, please contact me.
Thank you for your help.
2

Windows Batch

12K

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.