Computing.Net > Forums > Programming > Help creating a Batch file urgent

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Help creating a Batch file urgent

Reply to Message Icon

Name: zackuk
Date: November 22, 2007 at 07:24:33 Pacific
OS: Windows 2003
CPU/Ram: 1024
Product: Dell /power edge 2950
Comment:

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


SETLOCAL

SET_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




Sponsored Link
Ads by Google

Response Number 1
Name: Razor2.3
Date: November 22, 2007 at 07:40:36 Pacific
Reply:

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.txt

FOR /F "delims=" %%a IN (members.txt) DO CALL :Bkup "%%~a"
GOTO :EOF

:Bkup
ROBOCOPY "%_source%\%~1" "%_dest%\%~1" %_what% %_options%


0

Response Number 2
Name: zackuk
Date: November 22, 2007 at 08:38:29 Pacific
Reply:

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


0

Response Number 3
Name: Mechanix2Go
Date: November 23, 2007 at 07:14:48 Pacific
Reply:

Hi Razor2.3

Why the ~ in the sub?


=====================================
If at first you don't succeed, you're about average.

M2



0

Response Number 4
Name: Razor2.3
Date: November 23, 2007 at 07:18:53 Pacific
Reply:

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


0

Response Number 5
Name: Mechanix2Go
Date: November 23, 2007 at 08:07:43 Pacific
Reply:

cool

learn something every day

thanks



=====================================
If at first you don't succeed, you're about average.

M2



0

Related Posts

See More



Response Number 6
Name: zackuk
Date: November 27, 2007 at 02:21:47 Pacific
Reply:

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 Profiles

Also 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.


0

Response Number 7
Name: Razor2.3
Date: November 27, 2007 at 04:10:38 Pacific
Reply:

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 :EOF
If 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


0

Response Number 8
Name: zackuk
Date: November 27, 2007 at 04:17:05 Pacific
Reply:

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 script

if 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"


0

Response Number 9
Name: Razor2.3
Date: November 27, 2007 at 04:22:56 Pacific
Reply:

You're adding quotes in your SET _source=. Don't do that.


0

Response Number 10
Name: zackuk
Date: November 27, 2007 at 04:58:33 Pacific
Reply:

thanks i manage to get it work.
did the move finally.


0

Response Number 11
Name: zackuk
Date: December 4, 2007 at 02:53:02 Pacific
Reply:

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


0

Response Number 12
Name: zackuk
Date: December 4, 2007 at 03:04:14 Pacific
Reply:

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%


0

Response Number 13
Name: Mechanix2Go
Date: December 4, 2007 at 03:42:08 Pacific
Reply:

What is

LOG:



=====================================
If at first you don't succeed, you're about average.

M2



0

Response Number 14
Name: zackuk
Date: December 4, 2007 at 04:04:34 Pacific
Reply:

please ignore the log bit. i wanted the file to log the deleted directories in a text file


0

Response Number 15
Name: zackuk
Date: December 5, 2007 at 05:03:04 Pacific
Reply:

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
pause

Set _source="E:\Source profiles\"

FOR /F "delims=" %%a IN (new.txt) DO CALL :S %%~a

:S
RD /S % _source%\%%~a


0

Response Number 16
Name: zackuk
Date: December 5, 2007 at 07:55:55 Pacific
Reply:

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%\%~1

This 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.


0

Response Number 17
Name: zackuk
Date: December 5, 2007 at 09:49:47 Pacific
Reply:

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
pause

Set _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


0

Sponsored Link
Ads by Google
Reply to Message Icon






Post Locked

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


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Help creating a Batch file urgent

Help for create a batch file www.computing.net/answers/programming/help-for-create-a-batch-file/15796.html

Help creating a batch file www.computing.net/answers/programming/help-creating-a-batch-file/13059.html

Need help with a batch file www.computing.net/answers/programming/need-help-with-a-batch-file/17269.html