Filelisting to Directory creation

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
podgodd
Posts: 10
Joined: 14 Jan 2013 14:15

Filelisting to Directory creation

#1 Post by podgodd » 14 Jan 2013 14:22

Ok, the title sounds a little more simple than it seems. What I am trying to do is create a batch script where given a certain directory, say "z:\" creates a directory listing of certain file types (*txt). From there, the listing then would make the folder structure from the file list in a different mapped out location, say "m:\". Sorry if this sounds confusing; I am relatively new to batch commands and scripting. Also, this would save me several man hours.

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

Re: Filelisting to Directory creation

#2 Post by Squashman » 14 Jan 2013 14:45

So you want to create the directory structure of where your TEXT files are on one drive to another drive. That is pretty easily done with the XCOPY command. It has the /T switch to do that.

podgodd
Posts: 10
Joined: 14 Jan 2013 14:15

Re: Filelisting to Directory creation

#3 Post by podgodd » 14 Jan 2013 15:27

Squashman wrote:So you want to create the directory structure of where your TEXT files are on one drive to another drive. That is pretty easily done with the XCOPY command. It has the /T switch to do that.


My logic is this so far:

create a dir listing as follows:

dir /s /a:-d /b /o:n *.txt > Filelisting.txt

and then run:

for /f %d in (Filelisting.txt) do md %d

I just don't know how to get to the mapped location "M:\" and run it all in one script.

Like I said, I am new to all of this and just trying to make my life a little easier.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Filelisting to Directory creation

#4 Post by foxidrive » 14 Jan 2013 16:12

Try this:


Code: Select all

@echo off
dir /s /a:-d /b /o:n "Z:\*.txt" > Filelisting.tmp
for /f "delims=" %%d in (Filelisting.tmp) do md "M:\%%~pd" 2>nul
del Filelisting.tmp

podgodd
Posts: 10
Joined: 14 Jan 2013 14:15

Re: Filelisting to Directory creation

#5 Post by podgodd » 14 Jan 2013 16:37

foxidrive wrote:Try this:


Code: Select all

@echo off
dir /s /a:-d /b /o:n "Z:\*.txt" > Filelisting.tmp
for /f "delims=" %%d in (Filelisting.tmp) do md "M:\%%~pd" 2>nul
del Filelisting.tmp


If I have the source of the of the drive mapped to z:\ and the destination mapped to m:\ should I be able to run the batch command succesfuly from my desktop? I am trying to deduce this script and it seems like I need to have the script inside the z:\ drive. Is this correct? Thanks in advance for your all help guys.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Filelisting to Directory creation

#6 Post by foxidrive » 14 Jan 2013 17:18

The script can be anywhere that is writable.

If you have z: and m: mapped then it should create the folders ok.

podgodd
Posts: 10
Joined: 14 Jan 2013 14:15

Re: Filelisting to Directory creation

#7 Post by podgodd » 15 Jan 2013 09:44

foxidrive wrote:The script can be anywhere that is writable.

If you have z: and m: mapped then it should create the folders ok.



Foxdrive, thanks for the help! This world perfectly!

Post Reply