• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 199
  • Last Modified:

Bat file calling remote folder based on variable.

I am working on a BAT file and I am in need of assistance.

I need to call to a folder based on the name of the workstation the BAT file is running on.

For Example

My computer name is: NYCACT001

I use find out the location of the computer:

@echo off
setlocal
set Location=%ComputerName:~0,3%


So I have NYC as a variable.


Now using this variable I need to open a folder on a server

\\server1\share1 I can map a drive to it.

In this folder I have folders

NYC001
CHI002
LAX003
MSP004
DAL005
Etc.

What I need to do is match the NYC from the computer name and open the folder NYCxxx on the server regardless of the numbers at the end. And then simple copy the files from the folder to a local location.

Any advice is greatly appreciated.

Thank you

ChicagoMikeW
 
0
ChicagoMikeW
Asked:
ChicagoMikeW
  • 3
1 Solution
 
knightEknightCommented:
You can set another variable to the foldername like this:

for /f %%D in ('dir/ad %Location%*') do set fullLocation=%%D

Now you can copy files to/from %fullLocation%

0
 
knightEknightCommented:
sorry, forgot to specify the share:

for /f %%D in ('dir/ad \\server1\share1\%Location%*') do set fullLocation=%%D
0
 
knightEknightCommented:
(this assumes that there is only one folder for each city on the share -- that is there will not be a folder called NYC001 and another called NYC002 on the same share.)
0
 
ChicagoMikeWAuthor Commented:
Thank you.
0

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now