Solved Batch file to create and name a folder then copy files to it

January 23, 2014 at 04:32:02
Specs: Windows 7, 3.101 GHz / 8148 MB
How do I create a batch file, that will create a new folder in location F:\CH, and prompt me to enter the folder name, and then tell it to copy several files from F:\Accounts to the new folder?

Thanks,
Chris


See More: Batch file to create and name a folder then copy files to it

Report •

✔ Best Answer
January 23, 2014 at 18:56:01
@M2: i believe astroraptor has a point in that "setlocal" can be used independanly of either enable or disable of delayed-expansion, but as he pointed out, that point is moot in this case. I plagiarized your script to this:

@echo off & setLocal enableDELAYedeXpansioN

set N=
set /p N=new folder name ?
if not defined N goto :eof
md F:\CH\"!N!"|| goto :already
for %%a in ("file one.txt" "file two.xls" "file three.csv"...) do (
copy F:\Accounts\%%a F:\CH\"!N!"
rem optional, turn off Archive-bit: copy F:\Accounts\%%a F:\CH\"!N!" && attrib -A "%%a"
)
echo done.
goto :eof
:already
directory creation problem...

message edited by nbrane



#1
January 23, 2014 at 05:05:29
not tested

::====== script starts here ===============
::
:: chris.bat 2014-01-23 19:36:39.89
@echo off & setLocal enableDELAYedeXpansioN

set /p N=new folder name ?
md F:\CH\!N!
copy F:\Accounts F:\CH\!N!

::====== script ends here =================

=====================
M2 Golden-Triangle


Report •

#2
January 23, 2014 at 05:23:06
You don't even need EnableDelayedExpansion ... just %n%. Guaranteed that will work though.

message edited by astroraptor


Report •

#3
January 23, 2014 at 05:29:34
That's great, thanks for the quick response.
I think I wasn't quite specific enough though in my original question.

I have a lot of files and folders within the Accounts folder, but I only want to copy 9 files.
These 9 files get updated regularly but always maintain the same file name.
How do I modify the previous script to incorporate this?

Thank you.


Report •

Related Solutions

#4
January 23, 2014 at 18:56:01
✔ Best Answer
@M2: i believe astroraptor has a point in that "setlocal" can be used independanly of either enable or disable of delayed-expansion, but as he pointed out, that point is moot in this case. I plagiarized your script to this:

@echo off & setLocal enableDELAYedeXpansioN

set N=
set /p N=new folder name ?
if not defined N goto :eof
md F:\CH\"!N!"|| goto :already
for %%a in ("file one.txt" "file two.xls" "file three.csv"...) do (
copy F:\Accounts\%%a F:\CH\"!N!"
rem optional, turn off Archive-bit: copy F:\Accounts\%%a F:\CH\"!N!" && attrib -A "%%a"
)
echo done.
goto :eof
:already
directory creation problem...

message edited by nbrane


Report •

#5
January 30, 2014 at 01:18:05
Thanks all for your input on this. I've now got something together that works.

Chris


Report •

Ask Question