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
Batch File: Compare 2 text files and Update specific line in text file
I have 2 text files which I am comparing line by line.
- Check if the line is the same in both text files.
- If not, run a procedure to do something...
- Finally, update the line in the text file to match
The text files look something like this:
version_local.txt | version_server.txt ----------------- | ------------------ APP1 V5 | APP1 V5 APP2 V5 <--- | APP2 V8 <--- APP3 V4 | APP3 V4
The current solution I have creates a new line at the bottom of the text file but it does not replace the exact line.
@echo off set "file=C:\APPS\version_master.txt" set "ROOT_URL_SERVER=\\SERVER-SQL1\ClientDatabase\version_master.txt" set "ROOT_URL_LOCAL=C:\APPS\version_master.txt" FOR /F "delims=" %%a in ('FINDSTR /rc:"\<APP2\>" %ROOT_URL_SERVER%') DO SET @Check_Server=%%a FOR /F "delims=" %%a in ('FINDSTR /rc:"\<APP2\>" %ROOT_URL_LOCAL%') DO SET @Check_Local=%%a ECHO %@Check_Local% ECHO %@Check_Server% ECHO ============== REM Call Function to Update Versions call:Update_Version_Local :end pause ::-------------------------------------------------------- ::-- Function Update_Version_Local ::-------------------------------------------------------- :Update_Version_Local setlocal DisableDelayedExpansion for /f %%i in ('type "%file%"^|find /c /v ""') do set "current=%%i" <"%file%" >"%file%.tmp~" ( for /f "delims=" %%i in ('type "%file%"^|findstr /n "^"') do ( set "line=%%i" setlocal EnableDelayedExpansion for /f "delims=:" %%j in ("!line!") do if %%j EQU %current% ( echo(!@Check_Server! ) else ( echo(!line:*:=! ) endlocal ) ) move /y "%file%.tmp~" "%file%" goto:eof
version_local.txt ----------------- APP1 V5 APP2 V5 APP3 V4 APP2 V8 <---
My intention is to overwrite the 2nd line in this example to look like this:
version_local.txt ----------------- APP1 V5 APP2 V8 <--- APP3 V4
Find the number of rows in ~ 1000 CSV's using command
I'm running a process that produces n number of outputs at different timestamps for a given input CSV. The output files are in CSV form and labelled as such:
"Output" _ RouteName _ Direction _ YYMMDD _ HHMMSS
I have a macro that reports on missing data in the files, I just need a list of the number of rows in each CSV. I have been doing this by using the command:
@Echo Off :_Loop If "%~1"=="" Pause&Goto EOF Find /C /V "Wont@findthisin#anyfile" %1 >> LineCount.txt Shift Goto _Loop
The command is called counter.cmd and I just drag the output CSV's into it and it creates this output in a text file for each output:
---------- R:\10_TECHNICAL\10_TESTRUN\RUN\AM\ITN\A6_1N\OUTPUT_A6_1N_180313_070112.CSV: 5
The problem is that, I can only use this command to process a maximum of ~ 100 files, and I have ~ 1000 output files. When I try to make it do all 1000 files I get this error:
I have relatively basic windows command scripting skills and so don't know how to overcome this problem. Any help would be appreciated!
for /r not working with another for variable
My script iterates through a list of user profile paths and copies a bunch of files into them. This works so far now I need to edit the copied .xml files so I thought I'll just add another for /r for these folders and do my thing. But I can't get this script working and I really don't know why. It's only entering the for /r loop when I substitute !PATH! with a constant value.
SETLOCAL ENABLEDELAYEDEXPANSION for /f %%a in (users.txt) do ( SET PATH1=%%a\appdata\local\lazarus for /R "!PATH1!" %%x in (*.xml) do ( call :fart "DKIUSER" "%%a" "%%x" ) )
thats the content of my users.txt: C:\Users\DKIUSER C:\Users\dkiuser.DCJAN C:\Users\ladmin
Login and execute a query in sybase in a batch file
I am trying to login in sybase and right away execute a query in my batch file. This is the line:
dbisql -c "uid=dba;pwd=sql" -q select max(id)
But it does not work, if i just do:
dbisql -c "uid=dba;pwd=sql"
in the command line, it works and I can connect to the database but if I put the whole code it shows the following error:
Could not connect to the database. Database server not found SQLCODE : -100, OBDC 3 State = "08001" You are not connected to a database.
Can anyone help me, please? Thank you, guys.
Request Time outs while tracing an IP
Website URL: http://www.eforektisad.com Website IP: 220.127.116.11
So for some reason a week ago, the website stopped loading for some users, it opens like 1 out of 5 loads. Contacted the hosting company and they told me that i need to contact my ISP provider. This issue is only present for some users in Lebanon. So i tried to trace the IP to see whats happening and that's the trace result: https://i.stack.imgur.com/WsX34.png. I then tried it with a VPN on and it worked, thats the trace with a VPN on: https://i.stack.imgur.com/ngVv2.png. And I asked my friend in the US to trace it from there and thats the result: https://i.stack.imgur.com/swq3j.png. Theres a visible problem with the first trace. What should i tell my ISP to do? and any explanation why this is happening? since it was working fine a week ago.