i have a notepad file with a list of folder names. what i need is a batch file that will read from the text file and copy the folders and move it to a different directory then delete the folder afterwords. the folders are
E:\Student Home Directories\ESHomeDir
and needs to move to
E:\Student Home Directories\HS
the text file will be located in
E:\Student Home Directories\ES_Student_Dir _2B_deleted.txt
Thanks in Advance
and i plan on placing the batch file in the same directory
E:\Student Home Directories\
batch file to do sum bit thank you in advanced
Moderator: DosItHelp
Re: batch file to do sum bit thank you in advanced
Code: Select all
@echo off
setlocal enableextensions
set "src=ESHomeDir"
set "trgt=HS"
set "lst=ES_Student_Dir_2B_deleted.txt"
for /f "delims=" %%d in (%lst%) do (
xcopy "%src%\%%d\*" "%trgt%\%%d" /i /s/e /k/r/h /q && rd /s /q "%src%\%%d"
)
1st Student
2nd Student
3rd Student
Or if format is:
1st Student\
2nd Student\
3rd Student\
then remove "\" symbol from code "%src%\%%d\*"
Code: Select all
xcopy "%src%\%%d*" "%trgt%\%%d" /i /s/e /k/r/h /q && rd /s /q "%src%\%%d"
-
- Expert
- Posts: 442
- Joined: 01 Aug 2010 17:13
- Location: Canadian Pacific
- Contact:
Re: batch file to do sum bit thank you in advanced
You've almost got it right. I haven't used xcopy lately so I won't pretend to know what all the switches do, however, following your example this should do the job. Use enabledelayedexpansion to check if the current line ends with a \ or not. If it doesn't, append a \.
If you need to remove the backslash anywhere, switch !step! with !step:~0,-1!
Code: Select all
@echo off
setlocal enableextensions
setlocal enabledelayedexpansion
set "src=ESHomeDir"
set "trgt=HS"
set "lst=ES_Student_Dir_2B_deleted.txt"
for /f "delims=" %%d in (%lst%) do (
set "step=%%d"
if "!step:~-1!" NEQ "\" set "step=%%d\"
xcopy "%src%\!step!*" "%trgt%\!step!" /i /s/e /k/r/h /q && rd /s /q "%src%\!step!"
)
If you need to remove the backslash anywhere, switch !step! with !step:~0,-1!
Re: batch file to do sum bit thank you in advanced
This does not work if in the name presence exclamation markorange_batch wrote:Use enabledelayedexpansion...
The next code works with all these entries:
1st Student
2nd Student\
Stupidest Student!
Code: Select all
@echo off
setlocal enableextensions
set "src=ESHomeDir"
set "trgt=HS"
set "lst=ES_Student_Dir_2B_deleted.txt"
for /f "delims=" %%d in (%lst%) do (
xcopy "%src%\%%d.\*" "%trgt%\%%d" /i /s/e /k/r/h /q && rd /s /q "%src%\%%d"
)
-
- Expert
- Posts: 442
- Joined: 01 Aug 2010 17:13
- Location: Canadian Pacific
- Contact:
Re: batch file to do sum bit thank you in advanced
For some reason I confused you with the OP. I must have been sleepy.
!k could you explain how the inclusion of . changes the behaviour of:
xcopy "%src%\%%d.\*" "%trgt%\%%d" /i /s/e /k/r/h /q && rd /s /q "%src%\%%d"
?
!k could you explain how the inclusion of . changes the behaviour of:
xcopy "%src%\%%d.\*" "%trgt%\%%d" /i /s/e /k/r/h /q && rd /s /q "%src%\%%d"
?
Re: batch file to do sum bit thank you in advanced
The point neutralizes trailing backslash.orange_batch wrote:could you explain how the inclusion of . changes the behaviour
Code: Select all
@echo off
for %%i in ("%~dp0") do echo StartDirName = %%~nxi
for %%i in ("%~dp0.") do echo StartDirName = %%~nxi
pause