Home / Microsoft / Microsoft DOS / Copying File name and creating a folder wit the filename
0 Members and 1 Guest are viewing this topic. « previous next »
Pages: [1] - (Bottom) Print
Author Topic: Copying File name and creating a folder wit the filename  (Read 454 times)
eternity
Topic Starter
Newbie



Posts: 1


« on: November 13, 2009, 11:34:27 PM »

hi,
 I am looking for a batch file tat would copy the Filenames of Files and Create Folders for each filename and then move the files into the corresponding folder. i Googled but i couldnt find it out...
Kindly help me..... Thanx in advance...
IP logged
Two-eyes
Intermediate



Thanked: 4
Posts: 166




« Reply #1 on: November 15, 2009, 10:07:58 AM »

Hi there eternity

welcome to the Computer Hope Forums.  I hope you become a regular here and share your information with others.

Coming to your problem...
that was a tough one (mostly logical errors from me though ;)).

First I suggest reading:
1. how to use the for command.
Code: [Select]
for /?
should suffice.  OR go here.  (this is the same thing, but better look :))

2. about delayed expansion

Now,
I came up with the following code.  But to give you a background:
testtxt.txt contains these lines:
-txt1.txt
-txt2.txt
-txt3.txt

and the current folder has these files:
-test.bat
-texttxt.txt
-txt1.txt
-txt2.txt
-txt3.txt

Now, test.bat has this code:
Code: [Select]
@ECHO off

SETLOCAL EnableDelayedExpansion

FOR /F %%a IN (testtxt.txt) DO (
 SET name=%%~na
 MD !name!
 COPY %%~nxa !name!
)

You may use the XCOPY command instead of COPY, it has more functionality.  MOVE is unstable or something, but it is not usually recommended in these forums :).
Of course, adapt the code as you need it exactly.

Hope all this helped

Yours,
Two-Eyes %
IP logged

Quote
I believe the bushes in my yard will BURN before God picks up a PC to send a message

billrich
Guest
« Reply #2 on: November 15, 2009, 11:28:54 AM »


 I am looking for a batch file tat would copy the Filenames of Files and Create Folders for each filename and then move the files into the corresponding folder. I Googled but I couldnt find it out...
Kindly help me..... Thanks in advance...


Why?   Why a folder for each file?
« Last Edit: November 15, 2009, 11:52:19 AM by billrich » IP logged
gh0std0g74
Apprentice



Thanked: 37
Posts: 590


« Reply #3 on: November 15, 2009, 05:14:57 PM »


Why?   Why a folder for each file?
why not?
IP logged

Pages: [1] - (Top) Print 
Home / Microsoft / Microsoft DOS / Copying File name and creating a folder wit the filename « previous next »
 


Login with username, password and session length

Old Forum Search | Forum Rules
Copyright © 2010 Computer Hope ® All rights reserved.
Powered by SMF 2.0 RC3 | SMF © 2006–2010, Simple Machines LLC
Page created in 0.118 seconds with 20 queries.