Page 1 of 1
how to copy a folder by date?
Posted: 11 Dec 2010 10:22
by walter4991
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....
Re: how to copy a folder by date?
Posted: 11 Dec 2010 14:04
by aGerman
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
Re: how to copy a folder by date?
Posted: 12 Dec 2010 04:14
by walter4991
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 ...
I can explain the commands that you used? For example, what does "| |" or "& setlocal" and "latest =%% ~ a"??
thanks again ...
Re: how to copy a folder by date?
Posted: 12 Dec 2010 07:45
by aGerman
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
Re: how to copy a folder by date?
Posted: 12 Dec 2010 07:55
by walter4991
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)
Re: how to copy a folder by date?
Posted: 12 Dec 2010 08:09
by aGerman
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
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
Re: how to copy a folder by date?
Posted: 12 Dec 2010 08:37
by walter4991
sorry ... white space will not put them online is the translator that puts them ...
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?
Re: how to copy a folder by date?
Posted: 12 Dec 2010 08:53
by aGerman
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
Re: how to copy a folder by date?
Posted: 12 Dec 2010 09:10
by walter4991
yes yes I changed it does not work not even open the DOS window.
Re: how to copy a folder by date?
Posted: 12 Dec 2010 12:33
by aGerman
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
Re: how to copy a folder by date?
Posted: 12 Dec 2010 16:15
by walter4991
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 ...
Re: how to copy a folder by date?
Posted: 12 Dec 2010 18:02
by aGerman
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
Re: how to copy a folder by date?
Posted: 13 Dec 2010 10:02
by walter4991
ok wrote in ini file ... but to load the color insert before, the initiation of the batch?
Re: how to copy a folder by date?
Posted: 13 Dec 2010 11:09
by aGerman
Um, sorry ... what is the meaning of your last post
I don't get it.
Regards
aGerman