create dir with text file in it

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
muther
Posts: 2
Joined: 03 Jan 2012 16:15

create dir with text file in it

#1 Post by muther » 03 Jan 2012 16:21

I have a text file exported from the movie collectorz program and I want to add my DVD collection to xbmc through stub files. I found this code and modified it to give me the files.


Code: Select all

for /f "tokens=*" %%l in (aaa.txt) do echo %%l > "%%l.dvd.disc"


now I'm realizing I want to create a directory named from the list and place the created file into that directory. also I want to add the xml into the file -

Code: Select all

<discstub>
  <message>%moviename% is located in the DVD rack</message>
</discstub>





where "moviename" is taken from the aaa.txt file this is way beyond my tiny brains ability so I need help....LMAO

the text file looks like this...

The Adjustment Bureau (2010)
Alien (1979)
Aliens (1986)
Alien³ (1992)
Alien:_Resurrection (1997)
Alien Vs. Predator (2004)
Aliens Vs Predator - Requiem (2007)
Apollo 18 (2011)
Avatar (Extended_Cut) (2010)
Back To The Future (1985)
Back To The Future II (1989)
Back To The Future III (1990)


and I want to end up with...


a Dir named "The Adjustment Bureau (2010)" with a file named "The Adjustment Bureau (2010).DVD.Disc" in it and the file to contain the xml code from above with "The Adjustment Bureau (2010)" as the moviename.


I have spent hours trying different things and all have failed (and failed well I might add...LOL) I have almost 3,000 DVDS and would hate to have to do this by hand. and I'm sure others could use something similar

is a bat file the best thing to use? would vbs be better? anyone know of a program that will do this? any help or thoughts welcome.

Aacini
Expert
Posts: 1885
Joined: 06 Dec 2011 22:15
Location: México City, México
Contact:

Re: create dir with text file in it

#2 Post by Aacini » 03 Jan 2012 20:16

I think this Batch file do what you need:

Code: Select all

@echo off
for /F "delims=" %%l in (aaa.txt) do (
   if not exist "%%l" md "%%l"
   echo %%l > "%%l\%%l.dvd.disc"
   echo ^<discstub^>>> the_file.xml
   echo   ^<message^>%%l is located in the DVD rack^</message^>>> the_file.xml
   echo ^</discstub^>>> the_file.xml
)

Perhaps I didn't completely understand the point about the xml file, but I think you may fix this detail.

Squashman
Expert
Posts: 4465
Joined: 23 Dec 2011 13:59

Re: create dir with text file in it

#3 Post by Squashman » 03 Jan 2012 21:28

I believe they want the XML code written to the file %%L\%%L.DVD.DISC

muther
Posts: 2
Joined: 03 Jan 2012 16:15

Re: create dir with text file in it

#4 Post by muther » 04 Jan 2012 00:31

OK I got a working set of scripts. the first one makes the files and the second one creates a folder from the filename and moves the file into it.

Im running into one problem, some of the movies contain an ":" which screws that filename up. I've tried putting a ^ in front of the colon in the text file but this don't help. is there a way to replace it or parse it or clean it in the script?

Post Reply