1.

Solve : Folder Copying Complex Batch File?

Answer»

Hi, this is my first post on this site!

I have a little problem with a batch file I'm TRYING to create using command prompt in Windows XP. Basically here's the situation:

When the program runs, I want it to move ALL folders (including subfolders) from "C:\DOCUME~1\%USERNAME%\Desktop" that begin with "BTB " to the location "\\comp1\shareddocs".

It sounds easy, but I've tried using XCOPY and MOVE with no success. I just cant get the FOR loop correct; I have no idea how to read the "BTB " folder names into the FOR loop as variables.

Any help I can get is appreciated.

Thanks,

bloodghostSorry to db, but here's my current code (which doesn't work):

<----------------------------------------------------------------------
@ECHO OFF
setLocal EnableDelayedExpression
CLS
CD C:\DOCUME~1\%USERNAME%\Desktop
FOR /F "tokens=4 delims=" %%a IN ('DIR ^| FINDSTR /I /C:"BTB "') DO SET %%a=%folder%
CD %folder%
MD \\comp1\shareddocs\%folder%
XCOPY *.* \\comp1\shareddocs\%folder% /S /E /V /I /G /H
ECHO.
ECHO Copying, please wait...
RD /S /Q %folder%
ECHO.
PAUSE
---------------------------------------------------------------------->

I know its a little screwy, I'm not that good on my FOR loops. Please help!

Wasn't able to test this out. This may work but if it doesn't, we guarantee our work, so be sure to get back to us.

Code: [Select]@ECHO OFF
CLS
CD /d C:\DOCUME~1\%USERNAME%\Desktop
FOR /F "tokens=*" %%a IN ('DIR /a:d /b ^| FINDSTR /I /C:"BTB "') DO SET folder=%%a
CD "%folder%"
MD "\\comp1\shareddocs\%folder%"
XCOPY *.* "\\comp1\shareddocs\%folder%" /S /E /V /I /G /H
ECHO.
ECHO Copying, please wait...
RD /S /Q "%folder%"
ECHO.
PAUSE

Seriously, if you have any problems with the snippet LET us know. There are many knowledgeable people here that can help.



Discussion

No Comment Found