Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @echo off
- rem -- splits CSV file based on the values of the
- rem first two entries on each line
- rem --
- if "%~2" equ "" (
- echo ERROR: Destination folder is not set
- call :help
- goto :eof
- )
- if not exist "%~1" (
- echo ERROR: Source file does not exist
- call :help
- goto :eof
- )
- if not exist "%~2\" (
- mkdir "%~2\"
- )
- rem -- deleting all content in result folder to prevent
- rem data collisions
- rem --
- del "%~2\*" /Q /F >nul 2>&1
- set result_dir="%~2"
- rem -- getting the short name of source file to deal with eventual
- rem spaces in its name
- rem --
- set sourse=%~1
- echo\
- echo -- START SPLITTING `%~f1` --
- setlocal
- rem -- reading the first line of the CSV file --
- setlocal EnableDelayedExpansion
- for /f "usebackq delims=" %%a in ("!sourse!") do (
- endlocal
- set "firstline=%%a"
- goto :endloop
- )
- :endloop
- rem -- processing the lines of the CSV --
- for /f "usebackq skip=1 tokens=*" %%L in ("%sourse%") do (
- for /f "tokens=1,2 delims=, " %%S in ("%%L") do (
- rem -- the result file for each date is called
- rem after the first two values of the CSV line
- rem wich is also used as a notification for a
- rem changed date
- rem --
- if not exist %result_dir%\%%S%%T.txt (
- echo -- PROCESSING %%S%%T.txt --
- SETLOCAL ENABLEDELAYEDEXPANSION
- echo !firstline!>!result_dir!\%%S%%T.txt
- ENDLOCAL
- )
- ( echo %%L>>%result_dir%\%%S%%T.txt)
- )
- )
- endlocal
- echo -- SPLITTING FINISHED --
- call :info
- goto :eof
- :help
- echo USAGE:
- echo\
- echo %~n0%~x0 source_file destination_dir
- echo\
- echo source_file - path to the .csv file to process
- echo destination_dir - directory where the splited
- echo files will be stored.If does not exist
- echo will be created.
- echo All content there will be deleted
- echo\
- echo NOTE: For file names with spaces enclose patameters in double quotes
- call :info
- goto :eof
- :info
- echo\
- echo\
- echo -- Ver. 0.13
- echo -- Created by Vasil "npocmaka" Arnaudov
- echo -- Contact at npocmaka@gmail.com
- echo\
- goto :eof
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement