# 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.

#Requires -version 3.0
$WarningPreference="Continue" #variables$ScriptPath = $(Split-Path -Parent$MyInvocation.MyCommand.Definition)
#Log Timestamp
$logdate=Get-Date -Format ddMMyyyy_HHmmss$Logfile = "E:\Logs\FileProcessing_$logdate.txt" function LogWrite ([string]$logstring)
{
Add-content $Logfile -value$logstring
}
#Zip Files and move to backup folder
$sourcefolder="E:\Data"$backupFolder="E:\Data\Backup"

I am want to build script which will do housekeeping of logs, archive folder and log activity if any file deleted then mention the file name deleted and similaly if log file deleted then log it what files deleted.
if no files to delete for day then mention in the log file no files to delete.
Backup folder archive data should have 7 years, more then 7 years should do rotation (older files to delete and new files to keep).
Backup folder 7 years files to keep, after that older archive files to delete and newer archive file to keep it.
Log folder 1 years logs to keep, after that older log files to delete and newer log file to keep it.
0
hello i have a mining program running on W10pro which crashed from time to time. the OS appears fine and other application continue to run but the mining program will close.

i'm looking at all avenues of fixing this is the long term but as a short term fix i'd like help putting together a bat file that will do the following:

on OS boot up start MyProgram.exe automatically

If MyProgram.exe appears to close wait for say.... 30 seconds and restart MyProgram.exe
0
Hi
I need to rename some files

This works if I cd to the directory first

cd \s z:\Path\with\files\in
ren *.jpeg *.jpg


How do I write a simple bat file that takes the parent folder as a parameter and recursively  renames the files skipping over if the files exist

so if a folder had both MyCat.jpeg and mycat.jpg  it won't over right mycat.jpg (Windows file names are not case sensitive) and won't prompt
0
Hi,

Powershell coding:

I would like to first export all the users in AD that missing a displayname to a excel csv.
Then edit all the displaynames to the users that miss the displayname in that excel file.
Then use get-content to set-aduser to those displayname with the right account.

Anyway to do this?
0
Powershell scripting.

Dear expert

c:\test\01\test.txt
c:\test\02\test.txt
c:\test\03\test.txt
c:\test\04\test.txt

I need a script that take the first folder 01 file to another folder and then delete the 01 folder. Then it will stop here once removed 01 folder, next day i want the same progress with 02 folder and 03 etc.

0
i have multiple files to encrypt using slift software.
I have the manual steps to encrypt but need help for encrypting it.
I have restriction not to store any password in the scripts hence it required password to be encrypted.
command is
slift.exe /e "sourcedirectory" /pfx "privatekeyfile.pfx" password /cer "partnerpublickey.cer"
can help how to script in powershell.
0
Hello Everyone

I have recently updated my system to windows 10 from windows 7 and the following batch file i have to launch active directory and the lik on my system is no longer working as it comes up with the following. I had ran the command prompt as my ad min user and this was also elevated so i believe its my code but i would like pointers or even an easier way to do this.

--------------------------------------------------------------
Attempting to start "C:\Users\ME\Documents\Scripts\Toolbox.bat" /runas as user "Company\Admin13" ...
RUNAS ERROR: Unable to run - "C:\Users\ME\Documents\Scripts\Toolbox.bat" /runas
5: Access is denied.
--------------------------------------------------------------

hear is the batch file in all its glory

@echo off & setlocal enableDelayedExpansion

set /a size=80-1 & rem screen size minus one

if /i "%~1"=="/runas" goto Start
goto :eof
:Start

for /L %%# in (1,2,!size!) do if "!s:~%size%,1!" == "" set "s= !s! "
set s=!s:~1,%size%!& echo(!s!

:echo.
:set s=================
:for /L %%# in (1,2,!size!) do if "!s:~%size%,1!" == "" set "s= !s! "
:set s=!s:~1,%size%!& echo(!s!

:set s=Active Directory 32-Bit
:for /L %%# in (1,2,!size!) do if "!s:~%size%,1!" == "" set "s= !s! "
:set s=!s:~1,%size%!& echo(!s!
:start "" "dsa.msc" -32

echo.
set s=================
for /L

0
I have a script as below and I also have the .bat file for it in "X" downloads too.

Issue is when I running the script its merging the .bat file too.  Someone said to me about using robocopy but that would not work would it as I've merged into specific file name depending on how I answer in script?

Any ideas on how I can keep the script in "X" too and run it but when it runs it DONT merge the script so I can use next time I want to merge files.

@echo off
setlocal EnableDelayedExpansion

rem Define folder paths

set Empty=Y
for %%A in ("%BaseDir%\*.*") do set Empty=N
if "%Empty%" EQU "Y" (
echo No new files to process, quitting.
exit /b
)

if !ERRORLEVEL! EQU 1 (
) else (
if !ERRORLEVEL! EQU 1 (
)
)

rem Prompt for reference number
set RefNum=
set /P "RefNum=Enter reference number (blank to exit):"

rem If none entered, exit script
if "%RefNum%" EQU "" exit /b

rem Make a subfolder for the reference number

rem Move all files to new subfolder

Select all

Open in new window

0
Hello All,

I have done some simple interactive FTP batch scripts in the past, but I haven't worked with them in some time, I need to upload files individually to a Linux server from a Windows network share. I need to loop through the files on the network share directory and FTP those files to the Linux server so I can rename each one individually.  I have not done that before and have been beating my head for the last few days trying to find a solution.

Stan

Current environment:
Windows Server 2012
Linux : Red Hat

Current Flow:
Task Schedule calls the batch file
Interactive ftp move the files to ftp server.

Below I have included the batch file call and interactive ftp file.

This is the current flow:
-- Batch file is called from task scheduler

c:\ExportFiles.bat

--
REM MAP NETWORK DRIVE
NET use X: \\server\directory /PERSISTENT:NO

REM Changes directory to correct directory
X:
cd IT
cd Public
cd PTL

echo Server: server >> ftpLog.log

REM Start Time
echo Start FTP Date Time >> ftpLog.log
echo %date%-%time% >> ftpLog.log

REM Remove log file
REM del X:\IT\Public\PTL\ftpLog.log

REM Open connection to ftp server
ftp -i -s:C:\FTPBatchFileExport.txt >> ftpLog.Log

REM Archives files to Sent directory
Move X:\IT\Public\PTL\*.dat X:\IT\Public\PTL\Sent

REM End Time
echo  %date%-%time% >> ftpLog.log
echo End FTP Date Time >> ftpLog.log

C:
REM Removed mapped drive
NET…
0
I have two folders on two drives (c:\folder1 and d:\folder2 for example each with several sub directories). I want check the file names in folder1, in any sub directory,  and if the same file exists in folder2, in any directory, then delete the file in folder2. I don't care about comparing CRC, I just need to compare file names. I prefer to use two variables for the folder1 and folder2 because these folders will change from time to time. I need to write this in a .BAT or .VBS file.
0
Run a .bat file in background automatically and update the count whenever files are added
0
How to go to specific folder using batch script? And also count the no of files in that and display that with popup saying that "No of files added : ".
0
Hello all:

Hello all:
Currently I have the following set up: a directory with psftp.exe, my ppk file, and a batch file.  When I want to connect to the SFTP server, I open a cmd prompt, navigate to the directory and run the batch file.  It then connects me to the server.  I can then navigate to a folder and then upload a file running commands via the opened cmd prompt.

What I want to accomplish is doing all of this by calling a separate batch file (or something similar) from Access 2010.  So my thought is to run an external program (perhaps cmd prompt or powershell) using the Shell() function in Access, passing it the name of the file I want to put on the SFTP server.  The batch file (or whatever) would then do everything I normally do manually (open cmd, run batch file with credentials to log into the SFTP server, navigate to the directory on the server, and then put the file).

Is there a way to accomplish this through Access 2010?

Many thanks!

Juan
0
dear all

kindly someone help me with this issue , i have a lot of single pdf files and their names contain special character like " & ".
i need batch or VBA code to move each single pdf file to the folder with the same name.

0
I have a sql script that writes the selection into xml format. I am trying to write a batch file that will output this data into an xml file. Using :XML ON I am receiving the following error in the output file:

<?MSSQLError HResult="0x80004005" Source="Microsoft XML Extensions to SQL Server" Description="No description provided"?>
HResult 0x80004005, Level 16, State 1
No description provided

my .bat file code:
sqlcmd -i "ProductHierarchy-Dept-Cat-Subcat.sql" -S "SC-L-WINSQL-001" -d "HQ_L" -o "output.xml" -y0

If I turn :XML OFF it prints out the entire data selection into one line.

SET NOCOUNT ON
SET QUOTED_IDENTIFIER ON
SET ANSI_NULLS ON

--drop tables if exist
If(OBJECT_ID('tempdb..#importType') Is Not Null)
Begin
Drop Table #importType
End

--select data
If(OBJECT_ID('tempdb..#AMSprocuctHierarchy') Is Not Null)
Begin
Drop Table #AMSprocuctHierarchy
End

select
distinct DIM.pos_dept as Department,
SD.DESCRIPTION as DeptDesc,
--left(DIM.category,4) as Category,
--right(rtrim(DIM.category),4) as Subcategory,
DIM.upc as UPC, DIM.description as ItemDesc,
substring(DIM.CATEGORY, 1, 4) as Category,
substring(DIM.CATEGORY, 5, 8) as SubCategory,
CAT.DESCRIPTION as CategoryDesc,
subcat.DESCRIPTION as SubcatDesc
into #AMSprocuctHierarchy
from DHAT_ITEM_MASTER DIM
join store_department SD on DIM.pos_dept = SD.STORE_POS_DEPARTMENT
join CATEGORY subcat
on subcat.CATEGORY = DIM.CATEGORY
join CATEGORY cat
on

0
Dear Experts, is there any CMD or Powershell scripts to check domains' expiration dates?

Many thanks!
0
Greeting Experts,
I am in the process of creating a batch.bat script to install a Mcafee software on a remote computer using pxexec.exe.  When I get to the point of staring the install using command line string "C:\temp\setupeq.exe ADDLOCAL="tp"  /qn". The Windows User Access Control (UAC) stops the command from starting..... Can somebody give me some insight on how I can apply a workaround for this problem...
0
I'm working on a batch file. What I want to do is delete a reg key if there are no other sub-keys

ex. "HKLM\Software\Vendor" is the key I want to delete. Don't delete it if "HKLM\Software\Vendor\Product" exists
0
Hello experts,

I got the following command at: https://pureinfotech.com/delete-files-older-than-days-windows-10/
Very useful to set up directly through windows task scheduler

ForFiles /p "C:\path\to\folder" /s /d -30 /c "cmd /c del @file"


What I want is to enhance it by generating a log file in a specific folder in order to identify folders deleted.
The idea isn't to have a cumulative log file in order to avoid file increase but just to monitor last excution of the command.

0
Transpose () filenames from DIR & list them to txt or excel file either via CMD or Macro
The DIR contains sub folders, with files majorly of .tiff extension.

There is a logic while listing them and transpose.
Lets say there are 10 files in a sub folder. We manually rename a particular image in the example"0001_0001.tif" with additional "0001" which reflects as"0001_0001_0001.tif".

0001_0001_0001.tif
0002_0002.tif
0003_0001.tif
0004_0002.tif
0006_0001_0001.tif
0007_0005.tif
0007_0009.tif
0008_0010.tif

Requirement: The file names should be transposed and listed as per the breaker provided ie additional "0001.tif" . The output will look like.

DIR / Subfolder/0001_0001_0001.tif  0002_0002.tif 0003_0001.tif 0004_0002.tif

Thanks!
0
Bat, powershell, command to make IE start up upon login. Trying not to use GP.
1
The following code snipet is from the beginning of my big batch file. I need it to check if it has been run on the computer before, if not create that info, with '1', if it has been, then add 1 to that number.

Everything works outside if exist, but as soon as you put it inside the if statement, my debug code gives me just ranUUU and raaa with a space before it, what would indicate, that there is no varible.

Why does if exist make the varibles not work and how can I fix it?

echo off
setlocal
title AutoRasmus
mkdir C:\Laptopid.ee
attrib +h C:\Laptopid.ee
REM IF EXIST "C:\Laptopid.ee\rantimes.txt" (
set /p rantimes=<"C:\Laptopid.ee\rantimes.txt"
echo %rantimes% ranUUU
set /a rantimes=%rantimes%+1
echo %rantimes% raaa
echo %rantimes% > "C:\Laptopid.ee\rantimes.txt"
goto nxxx
REM ) ELSE (
REM echo else
REM echo 1 > C:\Laptopid.ee\rantimes.txt
REM set rantimes=1
REM goto nxxx
REM )
:nxxx
pause

0
Hi,
I need to use a command line tool to do some migration. This tool (an exe file) prompts "press any key to continue" before exit.
My goal is to create a batch script to do several migrations, one at a time, but at this stage it is unuseful because I need to press a key after each migration.
How can I "simulate" key pressing?
OS: Windows 10.
Thank you
0
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.

Thank you very much for your help.
0
In a batch file I am using a variable to get the files names with extension abc.bak (xyz.abc.bak)but 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
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.