Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

get the objFile.DateCreated for evaluation 1

Status
Not open for further replies.

zimbot

Programmer
Oct 16, 2007
11
0
0
US
Friends,

I have some code that I am struggling with..
my goal is to make a dir named 2007-10
and then move files that were created in the month of october in there.

I am very close ... I can make the dir
but I am having trouble with the evaluation

here is my code::::::::::::::

' :~:~:~:~:~:~:~:~:~:~:~:~:~:~:~:~:~:~:~:~:~:~:~:~:~:~:~:
' :~:~:~: script to tidy up ip_knox - js 10,07 ~:~:~:~:
' :~:~:~:~:~:~:~:~:~:~:~:~:~:~:~:~:~:~:~:~:~:~:~:~:~:~:~:
'
' makes a dir yyyy-mm :: Of Last Month , so if today is Oct it makes 9 , 2007-9
'
If not CreateObject("Scripting.FileSystemObject").FolderExists(Year(Date) & "-" & (Month(Date))-1) Then CreateObject("Scripting.FileSystemObject").CreateFolder(Year(Date) & "-" & (Month(Date))-1) End If
lstmo = (Year(Date) & "-" & (Month(Date))-1)
WScript.Echo "1st lst mo is " & lstmo
Set objFSO = CreateObject("Scripting.FileSystemObject")
objFSO.MoveFolder "C:\z\"& lstmo , "c:\zk\" & lstmo

WScript.Echo "this month is " & Month(Date)-0
''''
'''' now lets move some files
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder("C:\za") ' ''****> this would be d:\ip_knox good mov 4 ever

Set colFiles = objFolder.Files

'lstmo2 = DateAdd("m", -0, Now)
lstmo2 = (Year(Date) & "-" & (Month(Date))-0)
'WScript.Echo " 2nd lstmo is " & lstmo
'WScript.Echo " lstmo2 is " & lstmo2
For Each objFile in colFiles
'''''' here is the part that I cannot seem to get
''''''' as you can see I have tried a few things

'If objFile.DateCreated < lstmo2 Then
' If objFile.DateCreated < Now Then
'If objFile.DateCreated < DateAdd("m", -0, Now) Then
If objFile.DateCreated = Month(Date)-1 Then

'If DateDiff("d", objFile.DateCreated, Now) > 30 then


'WScript.Echo "I was made " & objFile.DateCreated
'WScript.Echo "comparing " & DateAdd("m", -0, Now)
'WScript.Echo "last month is " & Month(Date)-1

WScript.Echo "last month is " & DateAdd("m", -0, Now)

objFSO.copyFile objFile.Path, "C:\zk\" & lstmo & "\"
WScript.Echo "the path is " & objFile.Path

End If
Next

''''''''''''''''''''''''''''''''''''''''''''''''''''''

thanks in advance


 
[1] If the use of objFSO is wide-spread, create one and use all along.
[2] yyyy-mm usually means 2007-09 or 2007-10 etc. Do not use the shortened form 2007-9 for september. With the standard two-digit month, you can even compare yyyy-mm as the string would be well-ordered with respect to the common chronology.
[3] Device a standard yyyy-mm generating function for date type data for convenience.
[4] This is a no-nonsense rewrite for the functionality. (I don't get the meaning of c:\z for the first part. Why?)
[tt]
dim lstmo,objFSO,objFolder,colFiles,objFile

lstmo=get_yyyy_mm(dateadd("m",-1,date))

set objFSO=createobject("Scripting.FileSystemObject")
'this suppose c:\zk exists
If not objFSO.FolderExists("c:\zk\" & lstmo) Then
objFSO.CreateFolder("c:\zk\" & lstmo)
End If

'this suppose folder c:\za exists
Set objFolder = objFSO.GetFolder("C:\za") ' ''****> this would be d:\ip_knox good mov 4 ever
Set colFiles = objFolder.Files
For Each objFile in colFiles
If get_yyyy_mm(objFile.DateCreated) = lstmo Then
objFSO.copyFile objFile.Path, "C:\zk\" & lstmo & "\"
End If
Next

set colFiles=nothing
set objFolder=nothing
set objFSO=nothing

function get_yyyy_mm(d) 'd type date
get_yyyy_mm=year(d) & "-" & right("00" & month(d),2)
end function
[/tt]
 
Yes , I have heard that I am
making another objFSO when i can just reuse the one...
What can i say ,
I guess I thought : if I need one I need to make one ...
I understand that that is wrong - but have not changed it.
Or rather I changed it once ( when i changed lots of things )
and it all quit working... so I went back to a known working vers...

The ref to C:\z
objFSO.MoveFolder "C:\z\"& lstmo , "c:\zk\" & lstmo
Basically I am creating the dir lstmo in C:\z and then moving it to wher i need it c:\zk\.
You of course are wondering why do I not just make it where I need it... well, that is because...
1st I try to see if I can make a dir named what i wish

( and I have a dir on C called Z that I experiment in )
wow - "looky - I can make a dir named this year - last month.
Then I see if I can move it to where I need it.
then after 1 hour of google n such ... wow I can move a dir!

It is my practice to - once I have it all working - optimize things like that ... But I have not gotten this working so... you are seeing a lot of the pencil drawing before the painting.

My real sticking point is... the code will now copy everything from za to zk/lastm

and it is that last part that has me vexxed

======================( the code

' :~:~:~:~:~:~:~:~:~:~:~:~:~:~:~:~:~:~:~:~:~:~:~:~:~:~:~:
' :~:~:~: script to tidy up ip_knox - js 10,07 ~:~:~:~:
' :~:~:~:~:~:~:~:~:~:~:~:~:~:~:~:~:~:~:~:~:~:~:~:~:~:~:~:
'
' makes a dir yyyy-mm :: Of Last Month , so if today is Oct it makes 9 , 2007-9
'
If not CreateObject("Scripting.FileSystemObject").FolderExists(Year(Date) & "-" & (Month(Date))-1) Then CreateObject("Scripting.FileSystemObject").CreateFolder(Year(Date) & "-" & (Month(Date))-1) End If
lstmo = (Year(Date) & "-" & (Month(Date))-1)
WScript.Echo "1st lst mo is " & lstmo
Set objFSO = CreateObject("Scripting.FileSystemObject")
objFSO.MoveFolder "C:\z\"& lstmo , "c:\zk\" & lstmo

WScript.Echo "this month is " & Month(Date)-0
''''
'''' now lets move some files
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder("C:\za") ' ''****> this would be d:\ip_knox good mov 4 ever

Set colFiles = objFolder.Files

'lstmo2 = DateAdd("m", -0, Now)
lstmo2 = (Year(Date) & "-" & (Month(Date))-0)
'WScript.Echo " 2nd lstmo is " & lstmo
'WScript.Echo " lstmo2 is " & lstmo2
'((( here is the part that I cannot get right
'((( you can see I have tried several things
'((( and I have all those echos - trying to figure it out
For Each objFile in colFiles

'If objFile.DateCreated < lstmo2 Then
' If objFile.DateCreated < Now Then
'If objFile.DateCreated < DateAdd("m", -0, Now) Then
If objFile.DateCreated = Month(Date)-1 Then

'If DateDiff("d", objFile.DateCreated, Now) > 30 then


'WScript.Echo "I was made " & objFile.DateCreated
'WScript.Echo "comparing " & DateAdd("m", -0, Now)
'WScript.Echo "last month is " & Month(Date)-1

WScript.Echo "last month is " & DateAdd("m", -0, Now)

objFSO.copyFile objFile.Path, "C:\zk\" & lstmo & "\"
WScript.Echo "the path is " & objFile.Path

End If
Next
-----------------------------( end code

Thnaks
 
My notes have no intention to criticise the pencil sketch: the main plot is directly attacking the core functionality. Apparently, you've not understood it a bit. But, I leave you to meet the time you're actually ready.
 
I did not fully notice the change of 2007-9 to the 2007-09
.........
function get_yyyy_mm(d) 'd type date
get_yyyy_mm=year(d) & "-" & right("00" & month(d),2)
end function
............
I almost understand that.
yes I can see that ... that is better and you are creating it in th final destination ... good idea
Now if only I can scoop up everything w a creation date of
09 ( sept ) and move it into 2007-09

so unless I am wrong.

If get_yyyy_mm(objFile.DateCreated) = lstmo Then
objFSO.copyFile objFile.Path, "C:\zk\" & lstmo & "\"
End If
Next

also does not copy files w a creation date of 09 into the 2007-09 dir inside zk

are you sure this works ? ... could I have something wrong in my testing?
 
Before you doubt and jump to conclusion, watch the datecreated as shown in the context menu R on the file you said not being copied over.
 
Iwasn't taking any critisim...
and I do thnak you for your help...
what do you mean by " watch the datecreated as shown in the context menu R on the file you said not being copied over. "

menu R .... I , sorry , have not understood that iether.
I plead for your understanding.

Also... you have seen this work?

I have files files createddate september in the dir za
...what am i missing?

thanks very much
 
I wonder why
an echo like this
WScript.Echo "created is " & get_yyyy_mm(objFile.DateCreated)
does not return : created is 2007-10

and why isn't
If get_yyyy_mm(objFile.DateCreated) = get_yyyy_mm(dateadd("m",-1,date)) Then

the same as

If get_yyyy_mm(objFile.DateCreated) = lstmo Then
-------------------------------

dim lstmo,objFSO,objFolder,colFiles,objFile


WScript.Echo "hello"
lstmo=get_yyyy_mm(dateadd("m",-1,date))

set objFSO=createobject("Scripting.FileSystemObject")
'this suppose c:\zk exists
If not objFSO.FolderExists("c:\zk\" & lstmo) Then
objFSO.CreateFolder("c:\zk\" & lstmo)
End If

'this suppose folder c:\za exists
Set objFolder = objFSO.GetFolder("C:\za") ' ''****> this would be d:\ip_knox good mov 4 ever
Set colFiles = objFolder.Files
For Each objFile in colFiles
If get_yyyy_mm(objFile.DateCreated) = lstmo Then
''''If get_yyyy_mm(objFile.DateCreated) = get_yyyy_mm(dateadd("m",-1,date)) Then
WScript.Echo "created is " & get_yyyy_mm(objFile.DateCreated)

objFSO.moveFile objFile.Path, "C:\zk\" & lstmo & "\"
End If
Next

set colFiles=nothing
set objFolder=nothing
set objFSO=nothing

function get_yyyy_mm(d) 'd type date
get_yyyy_mm=year(d) & "-" & right("00" & month(d),2)
end function

-------------------------

seems like it should work - but I do not see it
 
1... I am certain that the files I have in c:\za are from 09. I have even used some diffrent ones..

I do not even see this work
objFSO.moveFile objFile.Path, "C:\zk\2007-09\"
. and I have read that I can Move the files ,
objFSO.copyFile now is
objFSO.moveFile
that is a better idea for me


full code............

dim lstmo,objFSO,objFolder,colFiles,objFile

lstmo=get_yyyy_mm(dateadd("m",-1,date))

set objFSO=createobject("Scripting.FileSystemObject")
'this suppose c:\zk exists
If not objFSO.FolderExists("c:\zk\" & lstmo) Then
objFSO.CreateFolder("c:\zk\" & lstmo)
End If

'this suppose folder c:\za exists
Set objFolder = objFSO.GetFolder("C:\za")
Set colFiles = objFolder.Files
For Each objFile in colFiles
If get_yyyy_mm(objFile.DateCreated) = lstmo Then
'objFSO.moveFile objFile.Path, "C:\zk\" & lstmo & "\"
objFSO.moveFile objFile.Path, "C:\zk\2007-09\"
End If
Next

set colFiles=nothing
set objFolder=nothing
set objFSO=nothing

function get_yyyy_mm(d) 'd type date
get_yyyy_mm=year(d) & "-" & right("00" & month(d),2)
end function
-------------------------------

 
Oh ....gee whizz , It is Oh so very humbling...
ya know ( yeah ... you knew ) those files I was testing with and then the others.... they all had creation dates bigger that september.
Boy do i have the red face

it works like a million bucks

so Thanks

On the upside , I have learned much.
I have learned the diff of date modified and date created
i have learned if you copy a file ..the copy has a new created date...:)

kinda funny in hindsight
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top