Specialty Forums
Security and Virus
General Hardware
CPUs/Overclocking
Networking
Digital Photo/Video
Office Software
PC Gaming
Console Gaming
Programming
Database
Web Development
Digital Home

General Forums
Windows XP
Windows Vista
Windows 95/98
Windows Me
Windows NT
Windows 2000
Win Server 2008
Win Server 2003
Windows 3.1
Linux
PDAs
BeOS
Novell Netware
OpenVMS
Solaris
Disk Op. System
Unix
Mac
OS/2

Drivers
Driver Scan
Driver Forum

Software
Automatic Updates

BIOS Updates

My Computing.Net

Solution Center

Free IT eBook

Howtos

Site Search

Message Find

RSS Feeds

Install Guides

Data Recovery

About

Home
Reply to Message Icon Go to Main Page Icon

Help creating a Batch file urgent

Original Message
Name: zackuk
Date: November 22, 2007 at 07:24:33 Pacific
Subject: Help creating a Batch file urgent
OS: Windows 2003
CPU/Ram: 1024
Model/Manufacturer: 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



Report Offensive Message For Removal


Response Number 1
Name: Razor2.3
Date: November 22, 2007 at 07:40:36 Pacific
Subject: Help creating a Batch file urgent
Reply: (edit)
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%


Report Offensive Follow Up For Removal

Response Number 2
Name: zackuk
Date: November 22, 2007 at 08:38:29 Pacific
Subject: Help creating a Batch file urgent
Reply: (edit)
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


Report Offensive Follow Up For Removal

Response Number 3
Name: Mechanix2Go
Date: November 23, 2007 at 07:14:48 Pacific
Subject: Help creating a Batch file urgent
Reply: (edit)
Hi Razor2.3

Why the ~ in the sub?


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

M2



Report Offensive Follow Up For Removal

Response Number 4
Name: Razor2.3
Date: November 23, 2007 at 07:18:53 Pacific
Subject: Help creating a Batch file urgent
Reply: (edit)
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


Report Offensive Follow Up For Removal

Response Number 5
Name: Mechanix2Go
Date: November 23, 2007 at 08:07:43 Pacific
Subject: Help creating a Batch file urgent
Reply: (edit)
cool

learn something every day

thanks



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

M2



Report Offensive Follow Up For Removal


Response Number 6
Name: zackuk
Date: November 27, 2007 at 02:21:47 Pacific
Subject: Help creating a Batch file urgent
Reply: (edit)
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.


Report Offensive Follow Up For Removal

Response Number 7
Name: Razor2.3
Date: November 27, 2007 at 04:10:38 Pacific
Subject: Help creating a Batch file urgent
Reply: (edit)
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


Report Offensive Follow Up For Removal

Response Number 8
Name: zackuk
Date: November 27, 2007 at 04:17:05 Pacific
Subject: Help creating a Batch file urgent
Reply: (edit)
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"


Report Offensive Follow Up For Removal

Response Number 9
Name: Razor2.3
Date: November 27, 2007 at 04:22:56 Pacific
Subject: Help creating a Batch file urgent
Reply: (edit)
You're adding quotes in your SET _source=. Don't do that.

Report Offensive Follow Up For Removal

Response Number 10
Name: zackuk
Date: November 27, 2007 at 04:58:33 Pacific
Subject: Help creating a Batch file urgent
Reply: (edit)
thanks i manage to get it work.
did the move finally.


Report Offensive Follow Up For Removal

Response Number 11
Name: zackuk
Date: December 4, 2007 at 02:53:02 Pacific
Subject: Help creating a Batch file urgent
Reply: (edit)
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

Report Offensive Follow Up For Removal

Response Number 12
Name: zackuk
Date: December 4, 2007 at 03:04:14 Pacific
Subject: Help creating a Batch file urgent
Reply: (edit)
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%


Report Offensive Follow Up For Removal

Response Number 13
Name: Mechanix2Go
Date: December 4, 2007 at 03:42:08 Pacific
Subject: Help creating a Batch file urgent
Reply: (edit)
What is

LOG:



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

M2



Report Offensive Follow Up For Removal

Response Number 14
Name: zackuk
Date: December 4, 2007 at 04:04:34 Pacific
Subject: Help creating a Batch file urgent
Reply: (edit)
please ignore the log bit. i wanted the file to log the deleted directories in a text file

Report Offensive Follow Up For Removal

Response Number 15
Name: zackuk
Date: December 5, 2007 at 05:03:04 Pacific
Subject: Help creating a Batch file urgent
Reply: (edit)
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


Report Offensive Follow Up For Removal

Response Number 16
Name: zackuk
Date: December 5, 2007 at 07:55:55 Pacific
Subject: Help creating a Batch file urgent
Reply: (edit)
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.


Report Offensive Follow Up For Removal

Response Number 17
Name: zackuk
Date: December 5, 2007 at 09:49:47 Pacific
Subject: Help creating a Batch file urgent
Reply: (edit)
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


Report Offensive Follow Up For Removal



Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: Help creating a Batch file urgent

Comments:

 
  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 


Data Recovery Software




XP Installed to G?

exessive internet traffic

ZoneAlarm Question. Blocked Connect

Windows Live Messenger Problem

Delete $Uninstall after SP3 updates


The information on Computing.Net is the opinions of its users. Such opinions may not be accurate and they are to be used at your own risk. Computing.Net cannot verify the validity of the statements made on this site. Computing.Net and Computing.Net, LLC hereby disclaim all responsibility and liability for the content of Computing.Net and its accuracy.
PLEASE READ THE FULL DISCLAIMER AND LEGAL TERMS BY CLICKING HERE

All content ©1996-2007 Computing.Net, LLC