copying the latest of some folders to a new destination

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Sebastian42
Posts: 22
Joined: 17 Feb 2017 02:28

copying the latest of some folders to a new destination

#1 Post by Sebastian42 » 30 Oct 2021 05:58

Some forum whose name I do not remember, kindly gave me the code to select the latest from a number of files, and copy it to a new destination. I do not understand the code at all, so cannot do the next step myself, but believe that it could be used as a template for copying the latest FOLDER to a new destination. I would like help from someone who understands this.

set source="C:\folderpath\filename"
set destination="C:\destinationpath\filename"

FOR /F "delims=" %%I IN ('DIR %source%\*.* /A:-D /O:-D /B') DO COPY %source%\"%%I" %destination% & echo %%I & GOTO :END
:END

aGerman
Expert
Posts: 4326
Joined: 22 Jan 2010 18:01
Location: Germany

Re: copying the latest of some folders to a new destination

#2 Post by aGerman » 30 Oct 2021 07:22

/A:-D explicitly excludes directories from being processed by DIR. In contrast, /A:D would only process directories.

Steffen

Sebastian42
Posts: 22
Joined: 17 Feb 2017 02:28

Re: copying the latest of some folders to a new destination

#3 Post by Sebastian42 » 30 Oct 2021 18:36

I made three changes; since no files are involved, but only folders, I removed 'filename' from the first two lines and removed the '-' in front of D. But the resulting code did not seem to do anything.

set source="C:\folderpath"
set destination="C:\destinationpath"

FOR /F "delims=" %%I IN ('DIR %source%\*.* /A:D /O:-D /B') DO COPY %source%\"%%I" %destination% & echo %%I & GOTO :END
:END

AR Coding
Posts: 30
Joined: 02 May 2021 21:16

Re: copying the latest of some folders to a new destination

#4 Post by AR Coding » 30 Oct 2021 22:31

I dont know if this helps but i fixed some quoteS

Code: Select all

set "source=C:\folderpath"
set "destination=C:\destinationpath"

FOR /F "delims=" %%I IN ('DIR "%source%\*.*" /A:D /O:-D /B') DO COPY "%source%\%%I" "%destination%" && echo %%I

Sebastian42
Posts: 22
Joined: 17 Feb 2017 02:28

Re: copying the latest of some folders to a new destination

#5 Post by Sebastian42 » 31 Oct 2021 04:36

The change in quotes seemed sensible but did not achieve functionality.

Intentionally or other wise, you made changes after "%destination%".
With or without those other changes, it still does not work.

aGerman
Expert
Posts: 4326
Joined: 22 Jan 2010 18:01
Location: Germany

Re: copying the latest of some folders to a new destination

#6 Post by aGerman » 31 Oct 2021 08:47

Code: Select all

FOR /F "delims=" %%I IN ('DIR "%source%\*.*" /A:D /O:-D /B') DO robocopy "%source%\%%I" "%destination%\%%I" /s /e /r:1 /w:1 &echo "%%I"&goto END
:END
Steffen

Sebastian42
Posts: 22
Joined: 17 Feb 2017 02:28

Re: copying the latest of some folders to a new destination

#7 Post by Sebastian42 » 31 Oct 2021 14:53

That worked ! Thank you.

Post Reply