1.

Solve : Resolved--- How to make a Batch file to copy folders from variable source??

Answer»

Hi,

sorry to barge in like this, but would really appreciate any help with this as I have been reading for hours now trying to find my answer..

can you drop a bat file in the Dir I specify to copy in that Dir that folder to a new folder in that Dir?
so without specifying the drive etc..
as it's for multiple users and I don't know where they have it installed (everyone has different installs/versions)
------------------------------------------------------------------------------------------------------

if you need background, the longer version   
why and what I'm trying to do with this batch file..
I'm a gamer/modder..
for a gaming community I made maps for a game, but will need to make a duplicate of the main game (mod) into a new mod..
to make it easier for the non technical members (copying manually).
and to keep download size down
(not having to make them download all the duplicate things as well)
I want to make BATCH file to copy the files from this main game folder to new folder (in same Dir)..

The problem is that everyone has different directory's they use to install their game,
so i can't just do:
copy (or xcopy, not sure the difference?!) "C:\programs\game\folder" C:\programs\game\new folder

I need to ask the people using this to specify (or maybe drop this batch file into) the main game Dir..
(the main game folder even varies..eg deluxe version)
eg   copy " \game\folder" \game\New folder
but this doesn't work so, how can I do that?


many thanks for your time people
you can:

1.(i see you have vista)

use where command to find executable of your game ex.
Code: [Select]H:\Users\_CORE7>where /R D:\ "crysis.exe"
D:\Program Files (x86)\Electronic Arts\Crytek\Crysis\Bin32\Crysis.exe
D:\Program Files (x86)\Electronic Arts\Crytek\Crysis\Bin64\Crysis.exe
D:\Program Files (x86)\Electronic Arts\Crytek\Crysis WARHEAD\Bin32\Crysis.exe
D:\Program Files (x86)\Electronic Arts\Crytek\Crysis Wars\Bin32\Crysis.exe
D:\Program Files (x86)\Electronic Arts\Crytek\Crysis Wars\Bin64\Crysis.exe
2.
let user input the path ex.
Code: [Select]H:\Users\_CORE7>set /p input=PATH:
PATH: C:\

H:\Users\_CORE7>echo %input%
C:\
3.
use dir command (longer version of where) ex.
Code: [Select]H:\Users\_CORE7>dir /s /b "D:\program files (x86)" |findstr "Crysis.exe"
D:\program files (x86)\Electronic Arts\Crytek\Crysis\Bin32\Crysis.exe
D:\program files (x86)\Electronic Arts\Crytek\Crysis\Bin64\Crysis.exe
D:\program files (x86)\Electronic Arts\Crytek\Crysis WARHEAD\Bin32\Crysis.exe
D:\program files (x86)\Electronic Arts\Crytek\Crysis Wars\Bin32\Crysis.exe
D:\program files (x86)\Electronic Arts\Crytek\Crysis Wars\Bin32\Crysis.exe.patch1
D:\program files (x86)\Electronic Arts\Crytek\Crysis Wars\Bin64\Crysis.exe

if you will use 1. or 3. then you need also for loop
Thank you very much devcom..

I should have stated though that I'm completely new to this.. sorry
I have no clue how to link this code to do a copy for the desired directory?
And actually I have been trying to do a bat file in a test Dir and can't get it working with the whole paths specified.. Here I thought, piece of cake
(when executing your 2nd code lines, I get 2 files dropped in the Dir?! )

maybe my mind is fried atm and should leave it for an other day,
but if you could help me how I would do this you would make my day


I think the second is my PREFERENCE, as that will cover all bases..

And while I'm at it , how you would exclude a folder within the folder to copy?
(i don't need to copy the Levels folder - being 3gig)


thank you very much again devcom,
i really appreciate it..  
I might have a try again TOMORROW with a fresh mind 




 I'm at a total loss 
I can't even seem to execute simple code that seems to work for everyone else 

I created this directory to test

xcopy /t /s /f "c:\folder\game\bf2142\" "c:\folder\game\2142DR\"

I get an error saying that "xcopy" is not recognized as an internal or external command?!

using just copy says the syntax of the line is incorrect?!
tried variations with that (eg - addressing a file within the folder) but same thing over and over...

I don't get it...

this is something i tried with your code devcom

Code: [Select]echo please enter the directory your main bf2142 folder is situated
echo.
echo off

H:\Users\_CORE7>set /p input=PATH:
PATH=C:\

H:\Users\_CORE7>echo %input%


pause

Xcopy /t /s /f "%input%=PATH:\bf2142\" "%input%=PATH:\2142DR\"
anyways, I thought I see what it does(did some variations).. and nothing is recognized, even "echo." is not a recognized command.. like what the?!?

please can anyone help me, I really want this to work.
otherwise my project would be jeopardized.. from a mere 180meg to nearly 2gig..
which is for many too much..
Being part of setting up a ladder competition starting off within a week or so, hoping to use my custom maps if i can get it finalized with a server provider..
and the people that signed up downloading and installing my content

thank you again..
all good, I have convinced the server provider to put the maps in with the rest of the game. So don't have to make a mod out of it..

If SOMEONE still would like to enlighten me with this problem, most welcome, as I still would like to learn this for some stage.
But thought to say that the pressure is off.

And thanks again Devcom..
you wrote me down quite some options of code there
awesome..

if any of your command doesnt work try this Code: [Select]http://www.technize.com/2007/05/14/your-command-prompt-doesnot-recognize-any-of-your-commands/
here is how this could look:

Code: [Select]echo off
setlocal enabledelayedexpansion

set modname=TEST
echo.SCANNING YOUR DISC FOR BF2142.exe

for /f "tokens=*" %%a in ('dir /b /s "D:\" ^|findstr "BF2142.exe"') do (
set _path=%%a
goto EXITLOOP
)

:EXITLOOP
set _path=%_path:BF2142.exe=%
set _path_mods=%_path%mods
set _path_bf2142=%_path%mods\BF2142

for /f "tokens=*" %%a in ('dir /b "%_path_bf2142%"') do (
if /I not "%%a" equ "LEVELS" if /I not "%%a" equ "MOVIES" (
echo copy "%_path_bf2142%\%%a" "%_path_mods%\%modname%\%%a" >>log.log
)
)

pause
log.log - just for testing
Code: [Select]copy "mods\bf2142\AI" "mods\TEST\AI"
copy "mods\bf2142\ClientArchives.con" "mods\TEST\ClientArchives.con"
copy "mods\bf2142\Common_client.zip" "mods\TEST\Common_client.zip"
copy "mods\bf2142\Common_server.zip" "mods\TEST\Common_server.zip"
copy "mods\bf2142\DefaultEnvMap.tweak" "mods\TEST\DefaultEnvMap.tweak"
copy "mods\bf2142\Fonts_client.zip" "mods\TEST\Fonts_client.zip"
copy "mods\bf2142\Fonts_server.zip" "mods\TEST\Fonts_server.zip"
copy "mods\bf2142\GameLogicInit.con" "mods\TEST\GameLogicInit.con"
copy "mods\bf2142\Ingame.mep" "mods\TEST\Ingame.mep"
copy "mods\bf2142\Init.con" "mods\TEST\Init.con"
copy "mods\bf2142\levels.md5" "mods\TEST\levels.md5"
copy "mods\bf2142\Localization" "mods\TEST\Localization"
copy "mods\bf2142\Logs" "mods\TEST\Logs"
copy "mods\bf2142\menu" "mods\TEST\menu"
copy "mods\bf2142\Menu_client.zip" "mods\TEST\Menu_client.zip"
copy "mods\bf2142\Menu_server.zip" "mods\TEST\Menu_server.zip"
copy "mods\bf2142\Mod.desc" "mods\TEST\Mod.desc"
copy "mods\bf2142\mod.png" "mods\TEST\mod.png"
copy "mods\bf2142\mod_icon.png" "mods\TEST\mod_icon.png"
copy "mods\bf2142\Objects" "mods\TEST\Objects"
copy "mods\bf2142\python" "mods\TEST\python"
copy "mods\bf2142\rain.con" "mods\TEST\rain.con"
copy "mods\bf2142\rain_heavy.con" "mods\TEST\rain_heavy.con"
copy "mods\bf2142\rain_light.con" "mods\TEST\rain_light.con"
copy "mods\bf2142\rain_medium.con" "mods\TEST\rain_medium.con"
copy "mods\bf2142\ServerArchives.con" "mods\TEST\ServerArchives.con"
copy "mods\bf2142\Settings" "mods\TEST\Settings"
copy "mods\bf2142\shaders" "mods\TEST\shaders"
copy "mods\bf2142\Shaders_client.zip" "mods\TEST\Shaders_client.zip"
copy "mods\bf2142\snow.con" "mods\TEST\snow.con"
copy "mods\bf2142\snow_heavy.con" "mods\TEST\snow_heavy.con"
copy "mods\bf2142\snow_light.con" "mods\TEST\snow_light.con"
copy "mods\bf2142\snow_medium.con" "mods\TEST\snow_medium.con"
copy "mods\bf2142\Sound_client.zip" "mods\TEST\Sound_client.zip"
copy "mods\bf2142\Sound_server.zip" "mods\TEST\Sound_server.zip"
copy "mods\bf2142\std_archive.md5" "mods\TEST\std_archive.md5"

i excluded LEVELS and MOVIES just for testThat is AWESOME!!

Your tha code man Devcom

And I suspect your familiar with bf2142 as well , seeing that you excluded the movie files also..
I didn't even think of that..

I will definitely be using this at some stage..
(maybe even still, now I got this )
very much appreciated..

ps.
didn't realize there was a rep button.. will come back after two hours to give you an other one well deserved..  least I can do..
 
dang.. the code seems to do it's thing, making a log file and all.
but it actually didn't make a copy in my mod folder?!
(the code didn't give me any errors, but was way to short.
seeming it didn't actually do anything beyond looking up the bf2142.exe ..
As it looks for that,
then you get the prompt to continue, and it exits out straight away?!

I assume you have tried it, so maybe there is something wrong with my PC?!
as that link you gave me, I did have a look at that and the dir's are in there.
So again the PC beats me..

anyways, I feel terrible that it won't work after all your effort into this.
that must have taken you some time to think up and type out..
 
sorry buddy..

well i dont know in what disc you have installed bf2142 i used D:\ ('dir /b /s "D:\" ^|findstr "BF2142.exe") as example you can also find on which disc user have bf:

Code: [Select]for %%a in (A B C D E F G H I J K L M N O P R S T U W X Y Z Q V) do (
if exist "%%a:\" (
for /f "tokens=*" %%b in ('dir /b /s "%%a:\" ^|findstr "BF2142.exe"') do (
set _path=%%a
goto EXITLOOP
)
)
)
but this can take much more time

also in my last code if you want to copy files you need to remove echo and  >>log.log
Code: [Select]echo copy "%_path_bf2142%\%%a" "%_path_mods%\%modname%\%%a" >>log.logor add this line
Code: [Select]copy "%_path_bf2142%\%%a" "%_path_mods%\%modname%\%%a"
then it should workHey devcom

I did overlook the echo bit , and it sort of worked after I took that out..
Well added a code to create a folder for the mod, as that was what stopped it at first as well..

It made all files into a folder though, and then put those files in that folder
eg. Fonts_client.zip made that the folder name, and put the actual zip file inside of that..
I tried with xcopy and some other things, and one just copied straight over without any folders (and contents of those folders) with some feature on it I can't remember and can't seem to find it again

this is what I came up with so far, as your multi drive search code didn't seem to work..
(I do have to say that this works but it still GOES from c to d, even when I put input d.. but no biggy, I just don't echo searching drive c: now .. coding is weird

Code: [Select]echo off
setlocal enabledelayedexpansion

CLS
:MENU
ECHO.
ECHO ...............................................
ECHO please select the drive your BF2142 is installed on.
ECHO ...............................................
ECHO PRESS C key for C: Drive
ECHO PRESS D key for D: Drive
ECHO PRESS E key for E: Drive
ECHO PRESS F key for F: Drive
ECHO ...............................................
ECHO.
ECHO.

SET /P M=Type C, D, E, or F then press ENTER:
IF %M%==C GOTO :CDrive
IF %M%==D GOTO :DDrive
IF %M%==E GOTO :EDrive
IF %M%==F GOTO :FDrive

:CDrive
set modname=2142DR
echo.SCANNING for your main BF2142 folder.

for /f "tokens=*" %%a in ('dir /b /s "c:\" ^|findstr "BF2142.exe"') do (
set _path=%%a
goto EXITLOOP
)

:DDrive
set modname=2142DR
echo.SCANNING for your main BF2142 folder.

for /f "tokens=*" %%a in ('dir /b /s "d:\" ^|findstr "BF2142.exe"') do (
set _path=%%a
goto EXITLOOP
)

:EDrive
set modname=2142DR
echo.SCANNING for your main BF2142 folder.

for /f "tokens=*" %%a in ('dir /b /s "e:\" ^|findstr "BF2142.exe"') do (
set _path=%%a
goto EXITLOOP
)

:FDrive
set modname=2142DR
echo.SCANNING for your main BF2142 folder.

for /f "tokens=*" %%a in ('dir /b /s "f:\" ^|findstr "BF2142.exe"') do (
set _path=%%a
goto EXITLOOP
)
)
)

:EXITLOOP
set _path=%_path:BF2142.exe=%
set _path_mods=%_path%mods
set _path_bf2142=%_path%mods\bf2142

for /f "tokens=*" %%a in ('dir /b "%_path_bf2142%"') do (
if /I not "%%a" equ "LEVELS" if /I not "%%a" equ "MOVIES" (
cls
mkdir "%_path_mods%\%modname%\%%a"
echo copy "%_path_bf2142%\%%a" "%_path_mods%\%modname%\%%a" >>log.log
xcopy /T /E "%_path_bf2142%\%%a" "%_path_mods%\%modname%\%%a"
copy "%_path_bf2142%\%%a" "%_path_mods%\%modname%\%%a"
)
)

pause
the last lines I also tried with just these with the same result..?!
(without xcopy)
Code: [Select]echo copy "%_path_bf2142%\%%a" "%_path_mods%\%modname%\%%a" >>log.log
copy "%_path_bf2142%\%%a" "%_path_mods%\%modname%\%%a"

This is getting somewhere though ..
thanks again..
ok here is my final code, tested works

Code: [Select]echo off
setlocal enabledelayedexpansion

set modname=TEST
echo.SCANNING YOUR DISC FOR BF2142.exe

for %%a in (A B C D E F G H I J K L M N O P R S T U W X Y Z Q V) do (
if exist "%%a:\" (
for /f "tokens=*" %%b in ('dir /b /s "%%a:\" ^|findstr "BF2142.exe"') do (
set _path=%%b
goto EXITLOOP
)
)
)

:EXITLOOP
set _path=%_path:BF2142.exe=%
set _path_mods=%_path%mods
set _path_bf2142=%_path%mods\BF2142

if not exist "%_path_mods%\%modname%" md "%_path_mods%\%modname%"

echo.>log.log

for /f "tokens=*" %%a in ('dir /b "%_path_bf2142%"') do (
if /I not "%%a" equ "LEVELS" if /I not "%%a" equ "MOVIES" (
robocopy "%_path_mods%\bf2142\%%a" "%_path_mods%\%modname%\%%a" || (
copy "%_path_mods%\bf2142\%%a" "%_path_mods%\%modname%\%%a"
)
)
)

cls
echo.DONE!
pause
this one use robocopy so if you want to give that "install" to someone else copy robocopy.exe from C:\Windows\System32 and add it to folder where script isAwesome, thanks a lot Devcom.

works a treat..



Discussion

No Comment Found