0

From path Y:\Server-MODS all files including those which are stored in subfolders, but not the subfolders themselves, but really only the files themselves are to be copied to the following path via xcopy C:\Users\User\Documents\My Games\FarmingSimulator2022\mods.

The basic code would look like this:

xcopy /s /h /y /d /q "Y:\Server-MODS" "C:\Users\Documents\My Games\FarmingSimulator2022\mods"

The copying works, but not the way I describe it above or the way I would like it to work.

I just want all the files, including the ones in the subfolders, to be copied, but not with the folder(s) where the file is in, just the file thrown together with the other files from the other subfolders?

1
  • how do you want the overwrite behavior to work? as lo-ol points out, this cannot be done with standard tooling, and requires a script instead Jun 20 at 4:20

2 Answers 2

1
Set-Location 'C:\Users\User\Documents\My Games\FarmingSimulator2022\mods'
(Get-ChildItem  -Path .\*.* -Recurse -File).FullName | Foreach {Copy-Item $_ 'F:\Server-MODS'}

@echo off 

cd /d "Y:\Server-MODS" || exit /b 
for /f delims^= %%i in ('2^>nul where /r "C:\Users\Documents\My Games\FarmingSimulator2022\mods" *.*')do 1>nul 2>nul copy /y "%%~fi" .

The copying works, but not the way I describe it above or the way I would like it to work.

:: Replace xcopy to Get-ChildItem .. | Foreach {Copy-Item ..} loop

/ :: Replace xcopy to for /f ..(where /Recursive )do.. loop + copy


/// Edit ///

  • Some suggestions on editing your answer and also the references (Additional resources) for some good practices knowledge for better understanding when using/creating bat scripts:
@echo off && setlocal EnableDelayedExpansion

color 1f && set "_sources=Y:\"
set "_destination=%UserProfile%\Documents\My Games\FarmingSimulator2022\mods"

for /r "%_source%" %%F in (*)do for %%A in ("%%~pF\.")do =;(
     echo\Von wo: "%%~nxA"
     echo\Welche Datei: "%%~nxF"
     xcopy "%%F" "%_destination%" /v /y /d
     echo\__________________________________ );=

echo\Ueberpruefe Dateien auf Nicht-Existenz auf der NAS...

for /r "%_destination%" %%F in (*)do set^ "_Found=False" & =;(
     for /r "%_source%" %%A in (*)do if "%%~nxF"=="%%~nxA" =;(
         set^ "_Found=True" ) else if "!_Found!" == "True" =;(
         del /q  "%%~fF" && echo\Datei geloescht: "%%~nxF" );=
        );=

echo\MODs sind synchron mit der NAS.
echo\__________ && timeout /t 05 | =;(
     echo\Druecke eine beliebige Taste, um das Fenster zu
     echo\schliessen, ansonsten wird das Fenster innerhalb
     echo\der naechsten 5 Sekunden geschlossen.
    );= & endlocal

Additional resources:

0
@echo off
color 1f
set "source=Y:\"
set "destination=C:\Users\User\Documents\My Games\FarmingSimulator2022\mods"




for /r "%source%" %%F in (*) do (
  for %%A in ("%%~pF\.") do (
    echo Von wo: "%%~nxA"
  )
  echo Welche Datei: "%%~nxF"
  xcopy "%%F" "%destination%" /v /y /d
  echo __________
)
echo Ueberpruefe Dateien auf Nicht-Existenz auf der NAS...
for /r "%destination%" %%F in (*) do (
  set "fileFound="
  for /r "%source%" %%A in (*) do (
    if /i "%%~nxF"=="%%~nxA" set "fileFound=true"
  )
  if not defined fileFound (
      del "%%F"
      echo Datei geloescht: "%%~nxF"
   
    )
  )


echo MODs sind synchron mit der NAS.
echo __________
echo Druecke eine beliebige Taste, um das Fenster zu schliessen, ansonsten wird das Fenster innerhalb der naechsten 5 Sekunden geschlossen.
timeout /t 5 >nul

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .