Need help with folder and files copy in CMD

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
remulus277
Posts: 2
Joined: 22 Feb 2017 07:20

Need help with folder and files copy in CMD

#1 Post by remulus277 » 22 Feb 2017 08:05

Hi,
I have setup a working batch script, which moves content of \\serverfolder\$username$ into the localcomputer $username$ OneDrive folder.
Sofar so good. but the problem is that i cant get the script to move files AND folders in the \\serverfolder\$username$
I cant find the code/syntax that moves not only files, but ALSO all folders with content. So i move the ENTIRE folder and all content. I tried using powershell, and also to use /ALL, /COPYALL, \*, \*.* etc parameters but i cant get it to Work.
I presume its the highlightend line (bold, underscore) where the code needs to be?
Can anyone help???
Thx:
------------------------------- my script ----------------------------------
@echo offrobocopy.exe "\\servername.domain.it-corp.net\homedirectory$\%username%" "C:\Users\%username%\OneDrive - EG A S\Gamle_H_Drev_Filer"
NET USE Z: \\servername.domain.it-corp.net\homedirectory$
NET USE W: \\servername.domain.it-corp.net\homedirectory$\Folders_synced_awaiting_OUmove_Then_Delete
MOVE Z:\%username% W:\
::Move c:\parentFolder\subFolder\*.* c:\parentFolder
NET USE Z: /delete
NET USE W: /delete
pause

pieh-ejdsch
Posts: 240
Joined: 04 Mar 2014 11:14
Location: germany

Re: Need help with folder and files copy in CMD

#2 Post by pieh-ejdsch » 22 Feb 2017 11:35

Is it now only to the integration of a folder in a path which already contains the same name folder? I think that is exactly the problem which occurs with you.

A batch which moves folders completely using MOVE is here:
https://www.administrator.de/contentid/193384#comment-791624
To use without call in seperate batch.
Or integrated in your batch as: SUB with:

Code: Select all

call :MoveintTree c:\parentFolder\subFolder c:\parentFolder /q

Code: Select all

:MoveintTree  Vollstaendige Integration beim verschieben von Ordnern 
@echo off
setlocal
if "%~1" equ "/?" goto :Help
if not exist "%~1" goto :Help
if not exist "%~2" goto :Help

set "List="
set "Quiet="
set "xcopyParam="
for %%i in (%3 %4 %5 %6) do (if /i "%%~i" equ "/L" set "List=echo"
  if /i "%%~i" equ "/Q" set "Quiet=%%~i"
  if /i "%%~i" equ "/U" call set "xcopyParam=%%xcopyParam%%%%~i "
  if /i "%%~i" equ "/D" call set "xcopyParam=%%xcopyParam%%%%~i "
)

 rem Verzeichnisse erstellen
if not defined List xcopy %xcopyParam% /TE "%~1\*" "%~2\"

set /a N=0
 rem Liste abarbeiten
for /f delims^= %%i in ('echo xva^|xcopy %xcopyParam% /LFSE "%~1\*" "%~2\" ^|Find /v "Datei(en) kopiert"') do (
  set File=%%i
  call :Move
)
echo %N% Datei^(en^) verschoben
if not defined List rd /s "%~1" %Quiet%
exit /b 0

:Move
set "File=%File: -> =*%"
for /f "tokens=1,2 delims=*" %%i in ("%File%") do if "%%j" neq "" %List% move "%%~i" "%%~j" >nul && set /a N+=1
exit /b


:help
echo Verschiebt den Inhalt der Quelle ins Ziel.
echo Loescht die Quelle auf Nachfrage.
echo(
echo Syntax: %~n0 Quelle Ziel [/L] [/U] [/D] [/Q]
echo(
echo  /L   Zeigt nur das Ergebniss an.
echo  /U   Verschiebt nur Dateien, die im Zielverzeichnis vorhanden sind.
echo  /D   Verschiebt nur Dateien, welche neuer als die im Ziel sind.
echo  /Q   Keine Nachfrage beim Loeschen der Quelle
exit /b


Please use CodeTags to make your script readable.

Phil

remulus277
Posts: 2
Joined: 22 Feb 2017 07:20

Re: Need help with folder and files copy in CMD

#3 Post by remulus277 » 23 Feb 2017 04:34

Hi Phil,

So i have to save the large batch you wrote, as MoveintTree.bat and then call this from another batch
with this command:

call :MoveintTree c:\parentFolder\subFolder c:\parentFolder /q''

or???

SIMMS7400
Posts: 546
Joined: 07 Jan 2016 07:47

Re: Need help with folder and files copy in CMD

#4 Post by SIMMS7400 » 23 Feb 2017 05:43

Use ROBOCOPY

Squashman
Expert
Posts: 4486
Joined: 23 Dec 2011 13:59

Re: Need help with folder and files copy in CMD

#5 Post by Squashman » 23 Feb 2017 07:26

remulus277 wrote:call :MoveintTree c:\parentFolder\subFolder c:\parentFolder /q''

or???

Using a colon is for calling a label within en existing batch file. If you need to run another batch file use CALL and I would get in the habit of specifying the extension with the program you are trying to run and quoting your parameters.

Code: Select all

call MoveintTree.bat "c:\parentFolder\subFolder" "c:\parentFolder" /q

Post Reply