how to copy a folder by date?

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
walter4991
Posts: 21
Joined: 11 Dec 2010 10:17

how to copy a folder by date?

#1 Post by walter4991 » 11 Dec 2010 10:22

how can I copy a folder by date?

I have three folders, and copy that I created to last ... how do I do?
(Of course in batch...)

PLEASE HELP ME....

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

Re: how to copy a folder by date?

#2 Post by aGerman » 11 Dec 2010 14:04

This may help:

Code: Select all

@echo off &setlocal

set "rootfolder=C:\where\the\folders\are\placed"
set "destination=C:\where\the\latest\folder\should\be\copied"

pushd "%rootfolder%" ||goto :eof
for /f "delims=" %%a in ('dir /ad /b /od') do set "latest=%%~a"
xcopy "%latest%" "%destination%\%latest%" /s/e/i/q/g/h/r/k/y
popd


Regards
aGerman

walter4991
Posts: 21
Joined: 11 Dec 2010 10:17

Re: how to copy a folder by date?

#3 Post by walter4991 » 12 Dec 2010 04:14

aGerman wrote:This may help:

Code: Select all

@echo off &setlocal

set "rootfolder=C:\where\the\folders\are\placed"
set "destination=C:\where\the\latest\folder\should\be\copied"

pushd "%rootfolder%" ||goto :eof
for /f "delims=" %%a in ('dir /ad /b /od') do set "latest=%%~a"
xcopy "%latest%" "%destination%\%latest%" /s/e/i/q/g/h/r/k/y
popd


Regards
aGerman


thanks a lot! works fine ... :mrgreen: :mrgreen:
I can explain the commands that you used? For example, what does "| |" or "& setlocal" and "latest =%% ~ a"??

thanks again ... :D

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

Re: how to copy a folder by date?

#4 Post by aGerman » 12 Dec 2010 07:45

walter4991 wrote:what does "||"

If pushd fails then goto :eof (quit the batch) will proceeded.

walter4991 wrote:or "& setlocal"

You probably don't need it. It's just to protect you from wrong values if you run several batch files in the same environment (e.g. by dropping them onto a a command prompt).

walter4991 wrote:and "latest=%%~a"??

The tilde (~) would remove enclosing quotes from the value in %%a.

Regards
aGerman

walter4991
Posts: 21
Joined: 11 Dec 2010 10:17

Re: how to copy a folder by date?

#5 Post by walter4991 » 12 Dec 2010 07:55

thanks a lot ... you are great ...
one last thing ... if I want to read a set of variables. ini file how can I do?
for example

Test.ini
color = fc
color = ab

batch
Set color1 = fc (reading from ini file)
Set color2 = 0A (reading from ini file)

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

Re: how to copy a folder by date?

#6 Post by aGerman » 12 Dec 2010 08:09

walter4991 wrote:Test.ini
color = fc
color = ab

Don't use the same value for different data and be careful with white spaces (also in your batch code).

Test.ini

Code: Select all

color1=fc
color2=ab




ReadIni.bat

Code: Select all

@echo off &setlocal
for /f "delims=" %%a in (Test.ini) do set "%%a"
echo %color1%
echo %color2%
pause

Regards
aGerman

walter4991
Posts: 21
Joined: 11 Dec 2010 10:17

Re: how to copy a folder by date?

#7 Post by walter4991 » 12 Dec 2010 08:37

sorry ... white space will not put them online is the translator that puts them ... :mrgreen: xD (I'm Italian)

This code does not work ...

Code: Select all

@echo off &setlocal
for /f "delims=" %%a in (Test.ini) do set "%%a"
echo %color1%
echo %color2%
pause


you have some other idea?

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

Re: how to copy a folder by date?

#8 Post by aGerman » 12 Dec 2010 08:53

Hmm, works fine for me.
Did you change the Test.ini according my example? What is the output?

BTW: Why did you translate code or the content of files?

Regards
aGerman

walter4991
Posts: 21
Joined: 11 Dec 2010 10:17

Re: how to copy a folder by date?

#9 Post by walter4991 » 12 Dec 2010 09:10

yes yes I changed it does not work not even open the DOS window. :(

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

Re: how to copy a folder by date?

#10 Post by aGerman » 12 Dec 2010 12:33

Show me the content of your INI file and your batch file (both enclosed in code tags). Otherwise I'm not able to see where it fails. As I said, the example worked for me.

Regards
aGerman

walter4991
Posts: 21
Joined: 11 Dec 2010 10:17

Re: how to copy a folder by date?

#11 Post by walter4991 » 12 Dec 2010 16:15

code of batch:

Code: Select all

call C:\stile.bat

set/p "cho=>>> "
if %cho%==0 goto SCELTA
if %cho%==1 goto NE-AZ

:NE-AZ
color 09
echo color 09>C:\stile.bat
cls
:BI-AZ
color f9
echo color f9>C:\stile.bat
cls


I would write the color in a file. ini and then when it starts the batch to read and set the color written nell'file. ini ...

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

Re: how to copy a folder by date?

#12 Post by aGerman » 12 Dec 2010 18:02

Try:

Code: Select all

@echo off &setlocal

if exist style.ini for /f "delims=" %%a in (style.ini) do set "%%a"

if not defined color (
  setlocal enabledelayedexpansion
  set /p "color=Enter a color combination: "
  color !color!
  >style.ini echo color=!color!
  endlocal
) else (
  color %color%
)

pause

Regards
aGerman

walter4991
Posts: 21
Joined: 11 Dec 2010 10:17

Re: how to copy a folder by date?

#13 Post by walter4991 » 13 Dec 2010 10:02

ok wrote in ini file ... but to load the color insert before, the initiation of the batch? :)

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

Re: how to copy a folder by date?

#14 Post by aGerman » 13 Dec 2010 11:09

Um, sorry ... what is the meaning of your last post :?
I don't get it.

Regards
aGerman

Post Reply