Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Your help will be deeply appriciated and many thanks---
Hi I need help writing a batch file.
I have a text file which contains usernames of all the users whose profiles need to be copied from one location on the network to the other location.
I have a batch file below
which copies all the user profiles, but i need this batch file to scan the text file members.txt then copy only those users profiles, whose user names are present in the text file.
Note: I will be using robocopy to go with it---------
@ECHO OFF
SETLOCALSET_source=E:\my.thingate\home\ThinGate.NET\Thingate2 Profiles
SET _dest=F:\DSO\Profile
SET _what=/Z /E /B /SEC /COPYALL
:: /COPYALL :: COPY ALL file info
:: /B :: copy files in Backup mode.
:: /SEC :: copy files with SECurity
SET _options=/R:0 /W:0 /LOG:F:\Scripts\profile\DSO_diskusage.txt
:: /R:n :: number of Retries
:: /W:n :: Wait time between retries
:: /LOG :: Output log file
ROBOCOPY %_source% %_dest% %_what% %_options%
-------thanks

Changes in red:
SET_source=E:\my.thingate\home\ThinGate.NET\Thingate2 Profiles
SET _dest=F:\DSO\Profile
SET _what=/Z /E /B /SEC /COPYALL
SET _options=/R:0 /W:0 /LOG:F:\Scripts\profile\DSO_diskusage.txtFOR /F "delims=" %%a IN (members.txt) DO CALL :Bkup "%%~a"
GOTO :EOF:Bkup
ROBOCOPY "%_source%\%~1" "%_dest%\%~1" %_what% %_options%

Hi Razor,
You are a star thanks for a quick response, I have tested the script and it works like a Charm.
I dont have words to thank you and the Forum.Zack

Hi Razor2.3
Why the ~ in the sub?
=====================================
If at first you don't succeed, you're about average.M2

To kill the quotes I'm passing in.
Quick example ('cause I'm not shopping and bored today):
C:\>copy con a.cmd
@echo %1
@echo %~1^Z
1 file(s) copied.C:\>a "Hello World"
"Hello World"
Hello World

cool
learn something every day
thanks
=====================================
If at first you don't succeed, you're about average.M2

Hi I tried to run the script in the production and apparently it got failed.
reason was there are some users in members.txt file who dont have their user directories at source loacation. SET_source=E:\my.thingate\home\ThinGate.NET\Thingate2 ProfilesAlso i want some changes to the script so it doesnt try to copy user profiles which are not presented in the source directory. i have to do this migration by tomorrow i.e 28th Nov2007any help will be greatly appriciated.

Also i want some changes to the script so it doesnt try to copy user profiles which are not presented in the source directory.
Easy enough. Just after the :Bkup line, add:IF NOT EXIST "%_source%\%~1" GOTO :EOFIf you wanted to, you could expand that to:SET_source=E:\my.thingate\home\ThinGate.NET\Thingate2 Profiles
SET _dest=F:\DSO\Profile
SET _what=/Z /E /B /SEC /COPYALL
SET _options=/R:0 /W:0 /LOG:F:\Scripts\profile\DSO_diskusage.txt
FOR /F "delims=" %%a IN (members.txt) DO CALL :Bkup "%%~a"
GOTO :EOF
:Bkup
IF NOT EXIST "%_source%\%~1" GOTO :err
ROBOCOPY "%_source%\%~1" "%_dest%\%~1" %_what% %_options%
GOTO :EOF
:err
@ECHO %~1>>notFound.txt

Here is what iam trying to run and it comes up with error WHICH IS GIVEN BELOW
@eho on
pause
:do u want to run the scriptif exist "%%~a" in "E:\\my.thingate\home\ThinGate.NET\Thingate2 Profiles" goto :doit
:doit
SET _source= "E:\my.thingate\home\ThinGate.NET\Thingate2 Profiles"SET _dest=F:\DSO\Profile
SET _what=/Z /E /B /SEC /COPYALL
SET _options=/R:0 /W:0 /LOG:F:\Scripts\profile\DSO_diskusage.txt
FOR /F "delims=" %%a IN (members.txt) DO CALL :Bkup "%%~a"
GOTO :EOF:Bkup
ROBOCOPY "%_source%\%~1" "%_dest%\%~1" %_what% %_options%
:end---------------
THE ERROR IS SHOWN BELOW
---------------NOTE: Read "True Replication" in Robocopy.Doc prior to first use of /MIR !
**** /MIR can DELETE files as well as copy them !
F:\scripts\Profile>CALL :Bkup "CALYX.001.dceurasp"F:\scripts\Profile>ROBOCOPY " "E:\my.thingate\home\ThinGate.NET\Thingate2 Profil
es"\CALYX.001.dceurasp" "F:\DSO\Profile\CALYX.001.dceurasp" /Z /E /B /SEC /COPYA
LL /R:0 /W:0 /LOG:F:\Scripts\profile\DSO_diskusage.txt---------------------
ROBOCOPY :: Robust File Copy for Windows :: Version XP010
---------------------Started : Tue Nov 27 11:14:51 2007
Source - F:\scripts\Profile\ E:\my.thingate\home\ThinGate.NET\Thingate2\
Dest - F:\scripts\Profile\Profiles\CALYX.001.dceurasp\Files :
Options : /COPY:DAT /R:1000000 /W:30--------------------
ERROR : Invalid Parameter #3 : "F:\DSO\Profile\CALYX.001.dceurasp"

Hi
I want to delete the profiles from the old location, hence I want a batch file which could look for user logins in members.txt file and if the user is found i want it to go and delete the user profile from old location.
is this possible? thanks for y our help in advance

Is this script correct ? for deleting profiles from old location?
@echo on
SET_source=E:\my.thingate\home\ThinGate.NET\Thingate2 Profiles
LOG:F:\Scripts\profile\DSO_profiledelete.txt
FOR /F "delims=" %%a IN (members.txt) DO CALL :Bkup "%%~a"
GOTO :EOF:Bkup
del /f /q "%_source%\%~1" "%_dest%\%~1" %_what% %_options%

What is
LOG:
=====================================
If at first you don't succeed, you're about average.M2

Hi
Given below is the batch file I am trying to run, everything seems to be working ok except that this batch file tries to delete the main folder which is source profiles. i dont want this to happen i tried a bit but a little help will be appriciated.thanks
@echo on:do you want to run this batch file
pauseSet _source="E:\Source profiles\"
FOR /F "delims=" %%a IN (new.txt) DO CALL :S %%~a
:S
RD /S % _source%\%%~a

This is the correct script
can any one help please@echo on
:do you want to run this batch file
pause
Set _source="E:\Source profiles\"
FOR /F "delims=" %%a IN (new.txt) DO CALL :S %%a
:S
RD /S %_source%\%~1This script after reaching the end of listed users in new.txt is trying to delete the Source Profiles Directory in the source.
I want the script to stop removing directories as soon as the last directory in listed in new.txt is deleted.

Dear All
many thanks for your help, I have manage to do it in the end.
Here is the script which does the job and it logs the details of deleted folders in notfound.txt file.
@echo on:do you want to run this batch file
pauseSet _source="E:\Source profiles\"
FOR /F "delims=" %%a IN (new.txt) DO CALL :S %%~a
goto :EOF
:S
IF NOT EXIST %_source%%~1 GOTO :err
RD /S /Q %_source%%~1
:err
@ECHO %~1>>notFound.txt
pause

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |