Variable source folder for batch file

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
tattooaussie
Posts: 3
Joined: 01 Feb 2011 09:18

Variable source folder for batch file

#1 Post by tattooaussie » 01 Feb 2011 09:27

Hi Guys,

I have an annoying issue that I have search all over the net for an answer, however to no avail.

Basically, I deploy many ClickOnce applications to clients. To enable automatic invoking of these applications via an internal business tool, I need to store the applicable files in a static directory.

So, can some help me with a batch file that can search for a specific filename (i.e. Client1application1.exe) in a folder structure that varies down the folder tree.

For example, I need to find application named Client1Application1.EXE. The default installation path by Microsoft is;
C:\Users\devtestserver\AppData\Local\Apps\2.0\CD6QG9E2.J22\OGNTBOXH.G17\unig..tion_1917d3bd69e1e31e_0001.0000_e2f9e6cf8ed8d8e3\Client1Application1.EXE

The static path here is C:\Users\devtestserver\AppData\Local\Apps\2.0\ at which point the rest of the folder path can be anything!

Thanks in advance.

alan_b
Expert
Posts: 357
Joined: 04 Oct 2008 09:49

Re: Variable source folder for batch file

#2 Post by alan_b » 01 Feb 2011 11:27

You know more than any script can know ! !

How do you expect the script to know that this is relevant :-
C:\Users\devtestserver\AppData\Local\Apps\2.0\

Are you expecting the script to select up to and including only the seventh instance of "\" ?
or is the fixed part always going to be exactly
C:\Users\devtestserver\AppData\Local\Apps\2.0\

Do you need to copy every EXE file in your static folder, or just a short cut or the path and or name ?

A batch script can find and display the path of Client1Application1.EXE via this command :-
DIR Client1Application1.EXE /S
and that path can be captured and used to copy your target to the static folder..

You need to explain with at least two typical executable's and their paths,
in which case please use "make believe" short concise examples that will fit on one display lline.

Alan

tattooaussie
Posts: 3
Joined: 01 Feb 2011 09:18

Re: Variable source folder for batch file

#3 Post by tattooaussie » 01 Feb 2011 11:55

Thanks Alan.

I took a look at the DIR command and that would be best suited in my case. I would appreciate some guidance or an example on how to capture and use the path returned from the DIR command.

The path up to the seventh instance of the "\" is always consistent. I need to copy every EXE file in the static folder.

Some (shorter) examples of the folder structure;

Source directory
C:\TestFolder\442424\Client1Application1.exe
C:\TestFolder\559349\Client2Application2.exe
C:\TestFolder\82132023211\Client3Application3.exe

Destination Directory
C:\Customer1\Client1Application1.exe
C:\Customer2\Client2Application2.exe
C:\Customer3\Client3Application3.exe

Many thanks for your assistance.

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Variable source folder for batch file

#4 Post by aGerman » 01 Feb 2011 14:56

I miss an information about the relation between source file and destination folder.
Client1Application1.exe to Customer1 :?:

For your last example you could try something like that:

Code: Select all

@echo off &setlocal

for /f "delims=" %%a in ('dir /a-d /b /s "D:\TestFolder\*.exe"') do (
  set "name=%%~na"
  setlocal enabledelayedexpansion
    set "name=!name:Client=!"
    for /f "delims=?" %%b in ("!name:Application=?!") do (
      md "D:\Customer%%b\" 2>nul
      copy "%%~a" "D:\Customer%%b\"
    )
  endlocal
)

pause

Regards
aGerman

alan_b
Expert
Posts: 357
Joined: 04 Oct 2008 09:49

Re: Variable source folder for batch file

#5 Post by alan_b » 01 Feb 2011 15:12

I think the initial requirement is now visible,
but I do not have time to develop/debug the script tonight.
Others may well give you the solution.

BUT BIG WARNING - POSSIBLY DOOMED TO DISASTER.

What will you do with the executable's once they are in your static folder ?

A "Click Once" action on the executable may fail to work if it is only one part of an application installation.
You may need a shortcut to the executable where it lives so it may function as designed.
There may also be software license restrictions that would allow shortcuts but prohibit copying from one source computer to a different destination computer.

Regards
Alan

tattooaussie
Posts: 3
Joined: 01 Feb 2011 09:18

Re: Variable source folder for batch file

#6 Post by tattooaussie » 02 Feb 2011 05:47

Many thanks aGerman, that worked perfectly.

Many thanks as well Alan for the comment regarding the possible disaster, I slightly amended the batch file to pick up the other files which have a standard qualifier.

Once again, thanks for your assistance.

Post Reply