[<<]Message[>>]    [<<]Author[>>]    [<<]Subject        [<<]Thread    

Number : 1698 Date : 2002-02-26 Author : rotaiv Subject : Re: Copying Source to Local Machine Size(KB) : 7
--=====================_-1428174316==_.ALT Content-Type: text/plain; charset="us-ascii"; format=flowed If you force the workstations to always map a drive, the batch file could reference the drive letter and not the UNC name. That way, it does not matter where the batch file resides so long as the workstations always use the same drive letter when executing the batch file. You could even have batch file look for itself and abort if it does not find itself. For example, if you insist on using the T: drive, the first line of the batch file could be: if exist t:\test.bat goto :Main echo Error - Could not find T:\TEST.BAT ... goto :Exit :Main xxcopy t:\ c:\temp I do have an alternative solution that will only work on NT/2000/XP workstations because it uses the enhanced variable substitution for file names. If you type "FOR /?" and look towards the end, you will see a number of variables beginning with the tilde (~). They will allow you parse file names into smaller components. Here is an example of a TEST.CMD batch file that uses it's current location as the source path: @echo off set SrcPath=%~dp0 set DstPath=c:\temp xxcopy %SrcPath% %DstPath% This batch can be executed by typing "\\server1\source\test.cmd". As I said earlier, this will not work on Windows 9X platforms as they do not support these types of variables. Another option is a "string manipulation" routine that can be accessed from a batch file and is aware of it's current path location. This "routine" has to be win32 compliant in order to support the UNC naming convention. That "routine" would then take the current path and strip out the name of itself. The end result would be the source location directory. One solution that comes to mind and will work on practically ANY platform is a Perl script. They can be compiled into an EXE so the clients do not need Perl installed on their machines. If you are interested in going this route, I can help out there also. rotaiv. At 02/26/2002 01:52 PM, wing_spand9 wrote: >Hello, > >I am trying to create a batch file that will copy source from a >network share to a local machine. I want my clients to go to a >location on the network, launch the batch file and it would copy the >files and directories in the source location to their hard drives. I >want to have the source files and the batch file located in the same >directory. I want the batch file to be smart enough to know what >network directory it is in so it can copy the source from the same >directory. So if the batch file and the source are moved to a >different network directory, the batch file would automatically know >that it has been moved and will copy the source from the new >directory. > >Example: > >Source Location: \\Server1\source\*.* >Batch File Location: \\server1\Source\batch.bat > >New Source Location: \\Server2\source\*.* >New Batch File Location: \\Server2\Source\batch.bat > >If the source is ever moved, I do not want to go back into the batch >file to change the static UNC source location line within the batch >file. I want the batch file to accept the Source Location as the >current network directory where the batch file and source is located. > >Any help you could provide would be greatly appreciated. > > > > > > >Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/ --=====================_-1428174316==_.ALT Content-Type: text/html; charset="us-ascii" If you force the workstations to always map a drive, the batch file could reference the drive letter and not the UNC name.  That way, it does not matter where the batch file resides so long as the workstations always use the same drive letter when executing the batch file.  You could even have batch file look for itself and abort if it does not find itself.  For example, if you insist on using the T: drive, the first line of the batch file could be:   if exist t:\test.bat goto :Main   echo Error - Could not find T:\TEST.BAT ...   goto :Exit   :Main   xxcopy t:\ c:\temp I do have an alternative solution that will only work on NT/2000/XP workstations because it uses the enhanced variable substitution for file names.  If you type "FOR /?" and look towards the end, you will see a number of variables beginning with the tilde (~).  They will allow you parse file names into smaller components.  Here is an example of a TEST.CMD batch file that uses it's current location as the source path:   @echo off   set SrcPath=%~dp0   set DstPath=c:\temp   xxcopy %SrcPath% %DstPath% This batch can be executed by typing "\\server1\source\test.cmd".  As I said earlier, this will not work on Windows 9X platforms as they do not support these types of variables. Another option is a "string manipulation" routine that can be accessed from a batch file and is aware of it's current path location.  This "routine" has to be win32 compliant in order to support the UNC naming convention.  That "routine" would then take the current path and strip out the name of itself.  The end result would be the source location directory. One solution that comes to mind and will work on practically ANY platform is a Perl script.  They can be compiled into an EXE so the clients do not need Perl installed on their machines.  If you are interested in going this route, I can help out there also. rotaiv. At 02/26/2002  01:52 PM, wing_spand9 wrote:   Hello, I am trying to create a batch file that will copy source from a network share to a local machine. I want my clients to go to a location on the network, launch the batch file and it would copy the files and directories in the source location to their hard drives.  I want to have the source files and the batch file located in the same directory. I want the batch file to be smart enough to know what network directory it is in so it can copy the source from the same directory. So if the batch file and the source are moved to a different network directory, the batch file would automatically know that it has been moved and will copy the source from the new directory. Example: Source Location: \\Server1\source\*.* Batch File Location: \\server1\Source\batch.bat New Source Location: \\Server2\source\*.* New Batch File Location: \\Server2\Source\batch.bat If the source is ever moved, I do not want to go back into the batch file to change the static UNC source location line within the batch file. I want the batch file to accept the Source Location as the current network directory where the batch file and source is located. Any help you could provide would be greatly appreciated. ------------------------ Yahoo! Groups Sponsor ---------------------~--> Tiny Wireless Camera under $80! Order Now! FREE VCR Commander! Click Here - Only 1 Day Left! http://us.click.yahoo.com/nuyOHD/7.PDAA/yigFAA/QzvwlB/TM ---------------------------------------------------------------------~->   Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/ --=====================_-1428174316==_.ALT--