Copying a file (in relative position) with .bat

Solved
Azep65 Posted messages 10 Status Membre -  
Azep65 Posted messages 10 Status Membre -
Good evening, I would like to copy a (or multiple) file(s) using a .bat command
My problem is that this .bat must be in a folder of a game and thus the path is not fixed. Is it really possible to do this or is it mandatory to have the full path?

Here is my game folder:
Minecraft2D\Maps\niveaux.lvl
to copy to
Minecraft2D\niveaux.lvl

Looking forward to any response, thank you all!

8 réponses

djdakta Posted messages 789 Registration date   Status Membre Last intervention   166
 
Hello,

Ideally, we would need the full path.
Here's the content of the .bat

@ECHO OFF
xcopy X:\Minecraft2D\Maps\niveaux.lvl Y:\Minecraft2D\niveaux.lvl /m /e /y

/m = copy only the updated files
/e = copy all subdirectories
/y = prompt for confirmation before overwriting

If there are spaces in the folder/file names, you need to use ""

xcopy "c:\source game" "x:\destination game" /m /e /y

--
Greetz from
Dj Dakta
2
Azep65 Posted messages 10 Status Membre
 
Thank you for the additional information!
Thanks djdakta, it's working well but I can't move the game's folder.
Do you think it's possible?
Otherwise, I was thinking of coding an app in C to create and copy the contents of the files.
The advantage is that the path can be based on the position of the .exe, but it's quite time-consuming to code..
I'll try all that and get back to you, thanks for your help.
0
djdakta Posted messages 789 Registration date   Status Membre Last intervention   166
 
Uhm... Do you want to copy the game folder elsewhere, or do you simply want to move it?
Maybe a silly question, but why are you so keen on having this folder copied/moved?
Isn't it fine where it is? ;-)

--
Greetz from
Dj Dakta
0
djdakta Posted messages 789 Registration date   Status Membre Last intervention   166
 


To move a folder or file(s):

MOVE [drive:] [path]filename destination

To rename a folder:

MOVE [drive:] [path]oldfoldername newfoldername

--
Greetz from
Dj Dakta
0
Azep65 Posted messages 10 Status Membre
 
Thank you, but that doesn't really solve my problem:
Basically, the game uses and modifies the files, so I'm looking to create a reset system.
Some files are placed in a master folder; they serve as originals (and will never be modified). Then, in another folder, there are the files modified by the game (child folder). The .bat file should COPY the master files into the child folder to replace and reset the files to their original state. Resetting them to zero (but not empty files).
I hope this explanation is more precise.
For now, it's working, but I can't move the game because the full path changes.
It may be impossible to do this with a .bat; I'm looking to do this in C, and I know it's possible, but it will take me some time to start.
I'll get back to you as soon as possible; thank you!
0
Pierrecastor Posted messages 10830 Registration date   Status Modérateur Last intervention   4 215
 
Hello

Here's a lead:

https://stackoverflow.com/questions/14936625/relative-path-in-bat-script

https://www.developpez.net/forums/d1504346/general-developpement/programmation-systeme/windows/scripts-batch/chemin-relatif-absolu/

Light a fire for someone and they will be warm for the rest of the day. Set a man on fire and he will be warm for the rest of his life.
-Terry Pratchett-
0
Azep65 Posted messages 10 Status Membre
 
It works at first glance, thank you, your link is very interesting, I will test it thoroughly tomorrow and I will post the code.
Thank you very much, my problem is getting solved!
0
Pierrecastor Posted messages 10830 Registration date   Status Modérateur Last intervention   4 215 > Azep65 Posted messages 10 Status Membre
 
I just typed "relative link batch" in a search engine, but nothing. ;-)

I must say that I knew it could be done easily in bash (Linux console), I thought it should be possible in batch, even though batch is light-years away from the possibilities offered by bash.
0
Azep65 Posted messages 10 Status Membre
 
So it works, but for each file it asks me if it's a folder or a file, so I have to type "F" each time and it's not practical at all..
Any idea?
0
dubcek Posted messages 18814 Registration date   Status Contributeur Last intervention   5 655
 
/i
If the Source parameter refers to a directory or contains wildcard characters and the Destination parameter is not specified, the xcopy command assumes that the name of the destination directory is destination and a new directory is therefore created. All files are then copied into this new directory. By default, the xcopy command prompts the user whether the destination is a file or a directory.
0
Azep65 Posted messages 10 Status Membre
 
Ok, so it's unavoidable..
In the end, I think it will never be perfect with a .bat (the scary aspect of the console, antivirus…) it's probably not suitable.
0
dubcek Posted messages 18814 Registration date   Status Contributeur Last intervention   5 655
 
hello
Here is my game folder:
Minecraft2D\Maps\niveaux.lvl
to be copied to
Minecraft2D\niveaux.lvl

copy file ..\..\niveaux.lvl
0
Azep65 Posted messages 10 Status Membre
 
Resolved, special program coded in C, it works perfectly.
The batch is good but it has some flaws, especially with antivirus...
0