1
1
I have a folder X:\Export
that has several folders:
X:\Export +---Export1 | \---various files … +---Export2 | \---… and subfolders +---Export3 | \---etc. \---etc. (names vary widely)
Each “Export” folder has the same subdirectory structure, but they have different files (with possibly some name collisions). I would like to copy all the subfolders and the files of X:\Export\Export1
, X:\Export\Export2
, X:\Export\Export3
, etc., to a folder X:\Export\merged
, keeping the subdirectory structure.
Pseudocode of what I would like to do but cannot get working properly:
create new folder "merged"
for (every folder X in a given directory Y (i.e., X:\Export)
copy every file in X keeping directory structure to "merged"
If conflict then overwrite
It works if run through command prompt from that directory, however if run by running the .bat file it defaults to c:\Windows. how can i make it run in the directory where the .bat is located
forgot to mention that occasionally this is on a network drive. – DjLenny – 2012-10-12T17:48:50.830
@DjLenny: “… if run by running the .bat file it defaults to C:\Windows.” I don’t understand how or why that would happen — what version of Windows are you running? But to fix the problem, put a
cd
into the script; e.g.,cd/d X:\Export
. If you need to be able to use it in different locations, make it take an argument (cd/d %1
). – Scott – 2012-10-12T19:24:29.560wondows 7, i figured out my problem, if i run it locally it works, if it is on an Unmapped network drive it doesnt work because of the UNC address of the file. Once i mapped the drive it worked just fine, also it worked in powershell. thanks for the script, works like a charm.
now a question for future understanding:
What is the relevance of "delims=" and ('dir /b /ad') the rest i understand' – DjLenny – 2012-10-12T21:39:10.250
@DjLenny: I added more explanation to my answer. (You can get even more information by typing
dir /?
andfor /?
.) If my answer solves your problem, please “accept” it. – Scott – 2012-10-12T22:35:29.453