getting Date modified into a string

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Ralf
Posts: 3
Joined: 17 Sep 2009 00:24

getting Date modified into a string

#1 Post by Ralf » 17 Sep 2009 00:41

Hey,

i'm trying to copy txt-files as backup into a zip-file. So far, so good...
The problem is that this bat-file is activated by several persons trough the all day, because its possible that some person changes the original txt-file. To keep a log in my backup-zip of all versions i was thinking to copy all txt-files in an temporary folder with in the new file-name the date that this file has been modified, so that i don't lose any version.

By the command ECHO i can get the date modified, but now i need to put this in a string to rename my original file when i copy this before zipping all files.

The echo-command:

FOR %%? IN (C:\Biblio_sql\Biblio_sql\*) DO (
ECHO File Name Only : %%~n?
ECHO File Extension : %%~x?
ECHO Name in 8.3 notation : %%~sn?
ECHO File Attributes : %%~a?
ECHO Located on Drive : %%~d?
ECHO File Size : %%~z?
ECHO Last-Modified Date : %%~t?
ECHO Parent Folder : %%~dp?
ECHO Fully Qualified Path : %%~f?
ECHO FQP in 8.3 notation : %%~sf?
ECHO Location in the PATH : %%~dp$PATH:?
)

What i'm trying to do :cry: :

COPY C:\Biblio_sql\Biblio_sql\* C:\Biblio_sql\Work_Folder\*~t?%.txt (but nothing here works...)


zip C:\Biblio_sql\Archive_sql.zip C:\Biblio_sql\Work_Folder\*.txt

ECHO erase C:\Biblio_sql\Work_Folder\*.txt

Thx a lot!!!

avery_larry
Expert
Posts: 391
Joined: 19 Mar 2009 08:47
Location: Iowa

#2 Post by avery_larry » 17 Sep 2009 09:08

Not sure I understand -- but is this what you want?


*UNTESTED*

Code: Select all

FOR %%? IN (C:\Biblio_sql\Biblio_sql\*) DO ( 
   ECHO File Name Only : %%~n?
   ECHO File Extension : %%~x?
   ECHO Name in 8.3 notation : %%~sn?
   ECHO File Attributes : %%~a?
   ECHO Located on Drive : %%~d?
   ECHO File Size : %%~z?
   ECHO Last-Modified Date : %%~t?
   ECHO Parent Folder : %%~dp?
   ECHO Fully Qualified Path : %%~f?
   ECHO FQP in 8.3 notation : %%~sf?
   ECHO Location in the PATH : %%~dp$PATH:?
   COPY "C:\Biblio_sql\Biblio_sql\%%~?" "C:\Biblio_sql\Work_Folder\%%~?%%~t?.txt"
)

Ralf
Posts: 3
Joined: 17 Sep 2009 00:24

#3 Post by Ralf » 18 Sep 2009 00:03

avery_larry wrote:Not sure I understand -- but is this what you want?


*UNTESTED*

Code: Select all

FOR %%? IN (C:\Biblio_sql\Biblio_sql\*) DO ( 
   ECHO File Name Only : %%~n?
   ECHO File Extension : %%~x?
   ECHO Name in 8.3 notation : %%~sn?
   ECHO File Attributes : %%~a?
   ECHO Located on Drive : %%~d?
   ECHO File Size : %%~z?
   ECHO Last-Modified Date : %%~t?
   ECHO Parent Folder : %%~dp?
   ECHO Fully Qualified Path : %%~f?
   ECHO FQP in 8.3 notation : %%~sf?
   ECHO Location in the PATH : %%~dp$PATH:?
   COPY "C:\Biblio_sql\Biblio_sql\%%~?" "C:\Biblio_sql\Work_Folder\%%~?%%~t?.txt"
)


Yes, you understood me perfect :wink:
An example what the result should be: some filename like test.txt modified on 15/09/2009 13:23 should be copied in an other folder as
test150920091323.txt, that's all. Only i can't get the date-time modified not in the name of my new file...
Your solution doesn't work :cry:
I get the following message: "The filename, directory name, or volume label syntax is incorrect."

Ralf
Posts: 3
Joined: 17 Sep 2009 00:24

#4 Post by Ralf » 18 Sep 2009 08:44

Ralf wrote:
avery_larry wrote:Not sure I understand -- but is this what you want?


*UNTESTED*

Code: Select all

FOR %%? IN (C:\Biblio_sql\Biblio_sql\*) DO ( 
   ECHO File Name Only : %%~n?
   ECHO File Extension : %%~x?
   ECHO Name in 8.3 notation : %%~sn?
   ECHO File Attributes : %%~a?
   ECHO Located on Drive : %%~d?
   ECHO File Size : %%~z?
   ECHO Last-Modified Date : %%~t?
   ECHO Parent Folder : %%~dp?
   ECHO Fully Qualified Path : %%~f?
   ECHO FQP in 8.3 notation : %%~sf?
   ECHO Location in the PATH : %%~dp$PATH:?
   COPY "C:\Biblio_sql\Biblio_sql\%%~?" "C:\Biblio_sql\Work_Folder\%%~?%%~t?.txt"
)


Yes, you understood me perfect :wink:
An example what the result should be: some filename like test.txt modified on 15/09/2009 13:23 should be copied in an other folder as
test150920091323.txt, that's all. Only i can't get the date-time modified not in the name of my new file...
Your solution doesn't work :cry:
I get the following message: "The filename, directory name, or volume label syntax is incorrect."


I got it and maybe it's also interesting for other people.

Here is the code:

@echo off
setlocal ENABLEEXTENSIONS
cd /D C:\Biblio_sql
FOR %%? IN (C:\Biblio_sql\Biblio_sql\*) DO (

ECHO Last-Modified Date : %%~t?
set amai=%%~n?
set wasdadde=%%~x?
call :runner %%~t?
)

dir c:\Biblio_sql\Biblio_sql\* > filenotexist.txt
goto :EOF


:runner
echo pattat = %1
echo time = %2
echo amai = %amai%
echo wasdadde = %wasdadde%
for /F "usebackq tokens=1,2 delims=:" %%x in (`echo %2`) do set friet=%%x%%y
echo de nieuwe frietjes = %friet%
:: set kroket=
for /F "usebackq tokens=1,2,3 delims=/" %%x in (`echo %1`) do set kroket=%%x%%y%%z
echo kroket=%kroket%
:: set saflet=
for /F "usebackq tokens=1" %%x in (`echo %kroket%`) do set saflet=%%x
echo saflet = %saflet%
COPY "C:\Biblio_sql\Biblio_sql\%amai%%wasdadde%" "C:\Biblio_sql\Work_Folder\%amai%_%saflet%_%friet%_%wasdadde%"

echo -------------------
sleep 5


::echo waarom zie ik de pause niet
echo variabelen = %saflet% %friet%
goto :EOF

Post Reply