Posts

Showing posts from March, 2017

DOS BATCH SCRIPTS

1. Had to frequently pull files from a server. The file set  used to be in following format. abc123_file1.txt def23145_file2.txt r4rtyyy_file3.txt The task was to remove the prefix from names and put the file set back. It was too mechanical, so I wrote following script to do the same. ECHO OFF SETLOCAL EnableDelayedExpansion FOR %%I IN (*) DO (    REM ECHO %%I    SET  xname=%%I      for /f "tokens=1,2 delims=_" %%a in ("%%I") do (      REM ECHO %%a      REM ECHO %%b        REM ECHO !xname!      SET xname=!xname:%%a_=!      REM ECHO !xname!      SET ENDSWITH=!xname:~-4!      REM ECHO !ENDSWITH!      IF "!ENDSWITH!"==".csv"  REN %%I  !xname!      IF "!ENDSWITH!"=="done"  REN %%I  !xname!    ) ) 2.  I faced  a situation where I needed to upload files to server at some intervals and not in one go. I was looking for a way to write script. This is what I did.  I was using winSCP  to upload the file.