get file creation date

D

Daniel

I have thousands of files that I need to sort by year. The only way I know
what the year is is by looking at the date created in the properties. I
need to know how to get date created from the file and then sort it into a
directrory.

Thank You,

Daniel
 
T

Tom Lavedas

Something like this might provide a foundation for what
you want ...

@echo off
for /f "tokens=3,6 delims=/ " %%a in (
'dir %1 /tc /a-d /o-d ^| find "/"') do (
if %%a==1999 echo 1: %%b
if %%a==2000 echo 2: %%b
if %%a==2001 echo 3: %%b
if %%a==2002 echo 4: %%b
if %%a==2003 echo 5: %%b)

Change the ECHO's to be a MOVE aimed at the correct
directories (on the same drive, if you don't want to
duplicate the files). Or use a 'CALL :SubroutineName ...'
to allow full processing.

Tom Lavedas
 
D

Daniel

Tom,

I am not very good at the batch thing, and I am a little confused (not the
first time). First, I replaced the echo with the move command and it said
"The system cannot find the drive specified." I tried to change the output
location, but I keep getting the same message. Where do I change the output
location? Also, can this work for Date Modified instead of Date Created?
Sorry to such a pain in the &^%, I really appreciate your help.

Thanks,

Daniel
 
T

Tom Lavedas

To change it to last modified, change the '/tc' to '/tw'
(see the DIR /? help for more info on this).

Concerning the MOVE, what did you use? I did NOT mean to
just replace ECHO with MOVE. I meant change the simple
example I provided with an echo statement to be a fully
formed MOVE statement.

From the MOVE /? help:
Moves files and renames files and directories.

To move one or more files:
MOVE [/Y | /-Y] [drive:][path]filename1[,...] destination

To rename a directory:
MOVE [/Y | /-Y] [drive:][path]dirname1 dirname2

[drive:][path]filename1 Specifies the location and name
of the fileor files you want to move.
destination Specifies the new location of
the file. Destinationcan consist of a drive letter and
colon, adirectory name, or a combination. If you are moving
only one file, you can also include a filename if you want
to rename the file when you move it.
[drive:][path]dirname1 Specifies the directory you want
to rename.
dirname2 Specifies the new name of the
directory.
/Y Suppresses prompting to confirm
you want to overwrite an existing destination file.
/-Y Causes prompting to confirm you
want to overwrite an existing destination file.

The switch /Y may be present in the COPYCMD environment
variable. This may be overridden with /-Y on the command
line. Default is to prompt on overwrites unless MOVE
command is being executed from within a batch script.
======== End =========

I can't write the MOVE statement, because I don't know
where you want to put the files. It should look something
like this ...

move %%b \some\destination\pathspec

Tom Lavedas
===========
 
D

Daniel

Tom,

I now understand how things are working, almost. This is what I am running:

rem @echo off
for /f "tokens=3,6 delims=/ " %%a in ('dir %1 /tw /a-d /o-d ^| find "/"') do
(
if %%a==1999 copy /Y %%b c:\temp\%%a These locations do exist.
if %%a==2000 copy /Y %%b c:\temp\%%a
if %%a==2001 copy /Y %%b c:\temp\%%a
if %%a==2002 copy /Y %%b c:\temp\%%a
if %%a==2003 copy /Y %%b c:\temp\%%a)

I am now getting a file not found message and I think it is because I am
getting the wrong file name, but am not sure. My output is as follows:
C:\temp><
if 2001 == 1999 copy /Y 183,187 c:\temp\1999
if 2001 == 2000 copy /Y 183,187 c:\temp\2000
if 2001 == 2001 copy /Y 183,187 c:\temp\2001
if 2001 == 2002 copy /Y 183,187 c:\temp\2002
if 2001 == 2003 copy /Y 183,187 c:\temp\2003The system cannot find the file specified.

=============END===============

Is the 183,187 the size of the file, or is it supposed to be the file name?
How do I get it to copy the correct file. Again I am sorry to be such a
pain.

Daniel




Tom Lavedas said:
To change it to last modified, change the '/tc' to '/tw'
(see the DIR /? help for more info on this).

Concerning the MOVE, what did you use? I did NOT mean to
just replace ECHO with MOVE. I meant change the simple
example I provided with an echo statement to be a fully
formed MOVE statement.

From the MOVE /? help:
Moves files and renames files and directories.

To move one or more files:
MOVE [/Y | /-Y] [drive:][path]filename1[,...] destination

To rename a directory:
MOVE [/Y | /-Y] [drive:][path]dirname1 dirname2

[drive:][path]filename1 Specifies the location and name
of the fileor files you want to move.
destination Specifies the new location of
the file. Destinationcan consist of a drive letter and
colon, adirectory name, or a combination. If you are moving
only one file, you can also include a filename if you want
to rename the file when you move it.
[drive:][path]dirname1 Specifies the directory you want
to rename.
dirname2 Specifies the new name of the
directory.
/Y Suppresses prompting to confirm
you want to overwrite an existing destination file.
/-Y Causes prompting to confirm you
want to overwrite an existing destination file.

The switch /Y may be present in the COPYCMD environment
variable. This may be overridden with /-Y on the command
line. Default is to prompt on overwrites unless MOVE
command is being executed from within a batch script.
======== End =========

I can't write the MOVE statement, because I don't know
where you want to put the files. It should look something
like this ...

move %%b \some\destination\pathspec

Tom Lavedas
===========
-----Original Message-----
Tom,

I am not very good at the batch thing, and I am a little confused (not the
first time). First, I replaced the echo with the move command and it said
"The system cannot find the drive specified." I tried to change the output
location, but I keep getting the same message. Where do I change the output
location? Also, can this work for Date Modified instead of Date Created?
Sorry to such a pain in the &^%, I really appreciate your help.

Thanks,

Daniel





.
 
T

Tom Lavedas

I'm not quite certain why you are getting this result.
The %%b variable does seem to be returning the file's size
instead of it's name, but I can't see quite why. The
directory listings should look something like this ...

08/06/2003 07:55a 301,989,888 pagefile.sys

which should make the sixth delimited item the file name,
because the only delimiters are the forward slash and
space. Clearly your system (XP?) is formatting the DIR
listing differently than my Win2000 Pro (SP4).

Try changing the tokens from 3,6 to 3,7. This should
work, unless there are (can be) spaces in the file's name
(something I failed to address in the original). In that
case, change the tokens definition to ...

... "tokens=3,6,* delims=/ " ...

And change the reference to %%b to "%%c" (this assumes the
file names begins in the seventh delimited location.

I hope that fixes it.

Tom Lavedas
===========
-----Original Message-----
Tom,

I now understand how things are working, almost. This is
what I am running:

rem @echo off
for /f "tokens=3,6 delims=/ " %%a in ('dir %1 /tw /a-d /o- d ^| find "/"') do
(
if %%a==1999 copy /Y %%b c:\temp\%%a These locations do exist.
if %%a==2000 copy /Y %%b c:\temp\%%a
if %%a==2001 copy /Y %%b c:\temp\%%a
if %%a==2002 copy /Y %%b c:\temp\%%a
if %%a==2003 copy /Y %%b c:\temp\%%a)

I am now getting a file not found message and I think it
is because I am getting the wrong file name, but am not
sure. My output is as follows:
C:\temp><
if 2001 == 1999 copy /Y 183,187 c:\temp\1999
if 2001 == 2000 copy /Y 183,187 c:\temp\2000
if 2001 == 2001 copy /Y 183,187 c:\temp\2001
if 2001 == 2002 copy /Y 183,187 c:\temp\2002
if 2001 == 2003 copy /Y 183,187 c:\temp\2003
The system cannot find the file specified.

=============END===============

Is the 183,187 the size of the file, or is it supposed to
be the file name? How do I get it to copy the correct
file. Again I am sorry to be such a pain.

Daniel
{rest snipped}
 
M

Mark V

Daniel wrote in
Tom,

I now understand how things are working, almost. This is what I
am running:

[ ]

Maybe you should Copy-Paste a few lines from your normal DIR output.
Perhaps the output format is different than the default and not being
parsed as expected.
 
D

Daniel

Thank You Tom,

I do have an XP system and I changed the token to 3,7 and left the %%b
veriable as it was and it worked perfectly. Thank you for your time and
help.

Daniel
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top