batch script to create folder and rename file

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
stevenwhite
Posts: 3
Joined: 05 Apr 2012 02:58

batch script to create folder and rename file

#1 Post by stevenwhite » 13 Apr 2012 04:51

Friends,

I need a batch script with the following:
- I have list of file say a.txt, b.txt, c.txt,d.txt and so on
- First it should create folder based on file name, like a,b,c,d and so on.
- Second, copy the files to respective folder, a.txt to folder a, b.txt to folder b and so on.
- Finally, all the files, in the respective folder, the file name should change to apple.txt. a.txt in folder a should rename to apple.txt, b.txt in folder b also rename to apple.txt. and so on.

Is that possible in batch script?

if so could someone pls help

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

Re: batch script to create folder and rename file

#2 Post by foxidrive » 13 Apr 2012 07:07

Untested: try it on some sample files.

Code: Select all

@echo off
for /f "delims=" %%a in ('dir *.txt /b') do (
md "%%~na" 2>nul
copy /b "%%a" "%%~na\apple.txt"
)

Post Reply