Category Archives: Batch

Batch

Windows CLI – Setting code page with CHCP

For those times when you are needing to set the command prompt export to UTF-8, it can be done on a temporary basis with ‘chcp 65001’ in the CLI. I’ve been working on achieving parity between the filename in a CSV and on the file system and because the file is rendered in UTF-8, the output of any CLI data needs to be the same so there’s actually a reason that you would want to do this.

Batch Python

Jupyter Notebook starting directory

We love Jupyter notebooks for data manipulation but it’s default starting directory is a bit of a pain on Windows. But you can override this behavior and specify the directory for it to start up with the following command, do make note of the backward slashes, not sure what that is all about but find and replace in normal mode in NPP and you’re golden.

jupyter notebook --notebook-dir="Z:/onedrive_tt/Archive/client/TCC_Touchpoints-Decommissioning/data/outbound"
Batch

Mute/Unmute System Volume

I work from home, so I have an office (room set aside as one) and I try to keep office hours but one of the things that no matter how hard I try, I fail to turn the volume on in the morning so I get notifications for meetings, email and IM’s and turn it off when leaving so I’m not hearing the notification for meetings, email and IM’s. You’d think this is fairly simple, you’d be thinking wrong.
I found a way to pass the pressing of the mute button and was able to schedule it for 8 am and 5 pm. Not elegant because if the mute is on at 5 pm it gets un-muted. It’ll work for now until I can look deeper into it.

Create a batch file that you’ll call with task scheduler. It’s one line:

powershell (new-object -com wscript.shell).SendKeys([char]173)
Batch

File – Data or No Data

A lot of the work we do for integration is of course automated. Sometimes we have to extract a data set and then use that export as the import to another integration. This is fine and well if there is data but if you have to run it every, let’s say, 5 minutes, there may very well be a situation where there isn’t anything to pick up. The matter is complicated by the fact that even if there isn’t any information there will be a header row.
This file is now completely useless and if left in place it will run through the process and wind up in the archive and produce a results file meaning you have to dig through empty files to try to find what’s going on.
To fix this I came across a batch file that will check the file and delete it if it has only a header row, a further check makes sure that that if any data is there is ignores the file. For your consideration and my reference here is the file that does this.

@echo off
setlocal enableExtensions disableDelayedExpansion

for %%a in ("..\..\data\inbound\*.csv") do (
   call :checkFile "%%~a"
   if errorlevel 1 del %%~a 
   echo File contains no content
)
endlocal
goto :eof


:checkFile
:: %~1   name of the file to check
:: returns 0 if file contains data, else 1 (== header only).

:: if file contains more than one line: data found
for /F "tokens=2 delims=:" %%a in ('find /c /v "" "%~1"') do (
   for /F "delims= " %%b in ("%%~a") do (
      if not 1 == %%~b exit /b 0
   )
)

:: if only line does not start with "Ident", then line contains data
for /F %%a in ('findstr /v "^Ident" "%~1"') do (
   exit /b 0
)

:: header only
exit /b 1