splitting a file into multiple files

March 9, 2011 at 07:41:44
Specs: Windows XP
Hey guys, i'm a total newb at Dos,
I need to split a master file up into multiple files. I need it to be split based on user name (Y:\name). There is some duplication that occurs, such as 1 user has 2 entries. Is there a way to split them based on user name?

This file's content looks like this:

Directory of Y:\Tom\AMP\KNOWLEDGE\Mgmt How To Videos

11/08/2010 09:02 AM 28,177,226 Finished File (FR).avi
11/08/2010 09:02 AM 23,537,194 Finished File.avi
11/08/2010 09:02 AM 20,185,404 Labels (FR) .avi
09/08/2010 12:18 PM 39,266,124 Labels .avi
09/08/2010 12:19 PM 33,422,756 Printing (FR).avi
09/08/2010 12:19 PM 21,128,992 Printing .avi

10 File(s) 291,024,488 bytes

Directory of Y:\John\My Pictures\24

01/11/2009 09:11 AM 21,874,732 Pictures Misc 2009 098.avi
1 File(s) 21,874,732 bytes

Directory of Y:\John\My Pictures\36

19/10/1998 10:22 AM 593,447 BADCHILD.avi
1 File(s) 593,447 bytes

Directory of Y:\Sam\My Documents

27/04/2004 08:29 PM 2,703,360 Mamanadi.avi
15/01/2004 09:11 AM 2,229,210 woman_helico_pilot.avi
12/10/2004 08:25 AM 720,896 WorldCupFever.avi
7 File(s) 13,529,562 bytes

Directory of Y:\andrew\1

25/06/1998 03:20 PM 619,325 HEIANN~1.AVI
1 File(s) 619,325 bytes


See More: splitting a file into multiple files

Report •


#1
March 9, 2011 at 07:56:03
I found a script that does what i need but it splits the file based on the last letter of the absolute path of a user file. Just need some help modifying so it uses the user name and not a single letter.

@echo off & setLocal EnableDELAYedExpansion

if exist file?.txt del file?.txt

for /f "tokens=* delims= " %%a in (Y_Drive_avi_03-2011-.txt) do (
set str=%%a
echo !str! | find "Directory of" > nul
if not errorlevel 1 (
set dest=!str!
if defined dest set dest=!dest:~-1!
)
if defined dest echo !str!>> file!dest!.txt
)


Report •

#2
March 10, 2011 at 04:16:43
:: ==========================================
::
:: cactus.bat Thu 10-03-2011 18:16:55.07
@echo off & setLocal enableDELAYedeXpansion

for /f "tokens=1-2* delims=\" %%a in (myfile) do (
if "%%a" equ "Directory of Y:" (
set D=%%b
type nul > !D!
) else (
echo.%%a >> !D!
)
)


=====================================
Life is too important to be taken seriously.

M2


Report •

#3
March 14, 2011 at 08:52:21
This did the trick
===================================================

@echo off &setlocal enabledelayedexpansion
for /f "delims=:" %%a in ('findstr /n "^" "masterfile.txt"') do set "last=%%a"

set /a n+=0
for /f "tokens=1* delims=:" %%a in ('findstr /n "Directory of " "masterfile.txt"') do (
for /f "tokens=2 delims=\" %%c in ("%%~b") do (
set /a end_!n!=%%a-1
set /a n+=1
set "start_!n!=%%a"
set "name_!n!=%%c"
set "end_!n!=%last%"
)
)

for /l %%a in (1,1,%n%) do (
if exist "!name_%%a!.txt" del "!name_%%a!.txt"
)

for /l %%a in (1,1,%n%) do (
set "range=false"
for /f "tokens=1* delims=:" %%b in ('findstr /n "^" "masterfile.txt"') do (
if %%b==!start_%%a! set "range=true"
if !range!==true (
>>"!name_%%a!.txt" echo(%%c
)
if %%b==!end_%%a! set "range=false"
)
)


Report •
Related Solutions


Ask Question