else inside a for loop batch
I’m trying to make a for /d loop but for some reason I can’t put an else statement in a for loop. I can put just an if inside a for loop but no if else what am I doing wrong
for /D %%i in (*) do ( if exist %%~fi%\Desktop.ini ( echo file found ) esle ( echo file not found ) )
See also questions close to this topic
How to copy files from one folder to another folder using xcopy or robocopy?
Below is the code to copy files from one folder to another folder and it works. However,I get new files generated everyday with small change in name. This code does not copy those new files when filename is simply modified.
@echo off setlocal disableDelayedExpansion set "file=" for /f "eol=: delims=" %%F in ('xcopy /dl "C:\Users\TMM\Desktop\fol2\*" "\\Folder2\TS\Test"') do ( if defined file ( setlocal enableDelayedExpansion copy "!file!" "\\Folder2\TS\Test" >nul && echo "!file!" || echo FAILED: "!file!" endlocal ) set "file=%%F" )
Batch script execution error "%%G was not expected"
I am trying to copy most recent log file in folder D:\Temp\ABC_logs to D:\Temp\ABC_logs\latest. Below is the code
@echo off set source=D:\Temp\ABC_logs set dest=D:\Temp\ABC_logs\latest pushd "%source%" for /f "tokens=*" %%G in ('dir *.log /b /a-d /od') do SET newest=%%G copy "%newest% "%dest%" popd
When I try to execute above code I get an error saying %%G was not expected. Please let me know what could be causing it.
.bat - ping list of IPs and reply with response time only
I'm stuck on this one, I've managed to create a batch file that imports list of IPs & hostnames but when I test for success or failure, I'd like to output how long it took. I don't know how to capture this and include it in the output. I'm trying to hide the default ping.exe output. Here's my code
@echo off for /F "tokens=1,2 delims= " %%A in (computers.txt) do ( rem ping -n 1 %%A | findstr /i "TTL=" | find "Reply" > nul if %errorlevel% == 0 ( echo %%B %%A successful ping in ?? Seconds echo %%B %%A successful ping [%date%, %time%] >> log.txt ) ) Pause
Import from SQL to CRM generates Process Exit Code when finished correctly
Ive created a job that weekly does a import from a file that contains alot of different values about already known customers, but also potential customers, and updates different tables in a SQL DB (SQL Server).
Normally this job takes around 3-5 hours, and the file is around 3-500mb, and it works fine. But now we got some a special happening regarding this kind of file which means that we have to import ten files with the size of 1.8gb each. This means that the import now takes around 15 hours for each file.
The import is structured like this:
- Import the file data to a table.
- Control all the rows in the table from step one and control if we already got the customer in our database(each row contains a customer). If we got the customer, we update our database with the values from the table we filled in step 1. Otherwise we create a new row with the data from the table in step 1.
- We run a .exe program which imports all the new data to CRM.
At the end of the import (step 3), all the data that we updated and imported looks fine, both in CRM and SQL, and all of the data that should be updated is updated correctly (all the data in the file). Instead of going on to the next step in the job (Its a SQL agent job) we get the following exception thrown and the job is aborted:
Process is terminated due to StackOverflowException. Process Exit Code -1073741571. The step failed.
I cant find anything about this errorcode. So i hope anyone here can help.
Adding variables from a text file to be used in URL path in batch file
I read several threads on similar issues but so far unable to find specific solution. I need to execute a batch file on a number of computers to repair a corrupted management agent. Because the agent is corrupted I cannot use the management system to resolve the issue and I have a tested solution that uses
I have a text file containing a list of computer names, is it possible to pull the computer names from the text file and use in the below batch file?
@echo off set compname=%computername% IF EXIST "\\%compname%\C$\Install\" GOTO CopyFile mkdir "\\%compname%\C$\Install\" :CopyFile copy "\\shareserver\sharefolder\AgentRepair.cmd" "\\%compname%\C$\Install\" wmic /NODE:%compname% /USER:domain\username /PASSWORD:password process call create "c:\Install\AgentRepair.cmd" exit
Any ping command alternatives
Is there any alternatives to the ping command in command prompt, windows 7? Im looking to flood my server with pings, but the ping command is blocked by administrators, im on my school computer. Does anyone have any ideas?