By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,851 Members | 1,118 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,851 IT Pros & Developers. It's quick & easy.

FSO question: create directory/subdir based on month/year

P: n/a
I want my application to maintain a directory tree based on months and
years, e.g.:

2004
January
file
file
file
February
file
file
...
Anyone have some FSO code that would do something similar to the following?
Grab the current date based on the system time
If user tries to do X action and the appropriate year directory doesn't
exist, create a directory named by the year (e.g. 2004)
If the appropriate month directory doesn't exist, create a subdirectory of
the appropriate year directory named by the month
Copy file (or do whatever) to the appropriate year/month directory based on
the current system time.

Thanks in advance.

-KF

Jul 19 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
<%
yearFolder = server.Mappath("/" & year(date()) & "/") & "\"
monthFolder = yearFolder & monthname(month(date())) & "\"

set fso = CreateObject("Scripting.FileSystemObject")
if not fso.folderExists(monthFolder) then
fso.createFolder monthFolder
if not fso.folderExists(yearFolder) then
fso.createFolder yearFolder
end if
end if

' now, you can copy anything to monthFolder

set fso = nothing

%>

Maybe a useful tutorial here?
http://www.aspfaq.com/2039

--
Aaron Bertrand
SQL Server MVP
http://www.aspfaq.com/


"Ken Fine" <ke*****@u.washington.edu> wrote in message
news:bt**********@nntp6.u.washington.edu...
I want my application to maintain a directory tree based on months and
years, e.g.:

2004
January
file
file
file
February
file
file
...
Anyone have some FSO code that would do something similar to the following? Grab the current date based on the system time
If user tries to do X action and the appropriate year directory doesn't
exist, create a directory named by the year (e.g. 2004)
If the appropriate month directory doesn't exist, create a subdirectory of
the appropriate year directory named by the month
Copy file (or do whatever) to the appropriate year/month directory based on the current system time.

Thanks in advance.

-KF

Jul 19 '05 #2

P: n/a
Ah, Aaron, so good, thanks so much. I already have the code running and am
madly writing millions of files to my filesystem with datetime stamps
concatinated to filenames. Soon I will be auto-categorizing photo uploads,
doing file maintenance, writing dynamic pages to static instances, and many
other cool things with the wonders of FSO.

Folks who want to play around with image management and manipulation in the
context of CMS-ey type stuff should look at the zImage component...I expect
I'll be able to do some pretty amazing things with this and a little FSO.

I think I noted a small error in the code you provided; I had to reverse the
sequence of checks on monthFolder and yearFolder to get this to work, as
shown below:

set fso = CreateObject("Scripting.FileSystemObject")

if not fso.folderExists(yearFolder) then
fso.createFolder yearFolder
if not fso.folderExists(monthFolder) then
fso.createFolder monthFolder
end if
end if
response.write monthFolder
'now, you can copy anything to monthFolder

Thanks again for all of your help.

-KF


"Aaron Bertrand [MVP]" <aa***@TRASHaspfaq.com> wrote in message
news:%2***************@tk2msftngp13.phx.gbl...
<%
yearFolder = server.Mappath("/" & year(date()) & "/") & "\"
monthFolder = yearFolder & monthname(month(date())) & "\"

set fso = CreateObject("Scripting.FileSystemObject")
if not fso.folderExists(monthFolder) then
fso.createFolder monthFolder
if not fso.folderExists(yearFolder) then
fso.createFolder yearFolder
end if
end if

' now, you can copy anything to monthFolder

set fso = nothing

%>

Maybe a useful tutorial here?
http://www.aspfaq.com/2039

--
Aaron Bertrand
SQL Server MVP
http://www.aspfaq.com/


"Ken Fine" <ke*****@u.washington.edu> wrote in message
news:bt**********@nntp6.u.washington.edu...
I want my application to maintain a directory tree based on months and
years, e.g.:

2004
January
file
file
file
February
file
file
...
Anyone have some FSO code that would do something similar to the

following?
Grab the current date based on the system time
If user tries to do X action and the appropriate year directory doesn't
exist, create a directory named by the year (e.g. 2004)
If the appropriate month directory doesn't exist, create a subdirectory of the appropriate year directory named by the month
Copy file (or do whatever) to the appropriate year/month directory based

on
the current system time.

Thanks in advance.

-KF


Jul 19 '05 #3

P: n/a
I had nested them with this logic in mind: "if the month folder doesn't yet
exist, then we know we have to create the month folder. We might *also*
have to create the year folder." I didn't test it thoroughly, but it
certainly seems like it should work as written. I'm not sure how you can
expect the yearFolder check to return false but the monthFolder to return
true. If the monthFolder returns true, we don't have to check if its parent
exists...

--
Aaron Bertrand
SQL Server MVP
http://www.aspfaq.com/


"Ken Fine" <ke*****@u.washington.edu> wrote in message
news:#F**************@TK2MSFTNGP12.phx.gbl...
Ah, Aaron, so good, thanks so much. I already have the code running and am
madly writing millions of files to my filesystem with datetime stamps
concatinated to filenames. Soon I will be auto-categorizing photo uploads,
doing file maintenance, writing dynamic pages to static instances, and many other cool things with the wonders of FSO.

Folks who want to play around with image management and manipulation in the context of CMS-ey type stuff should look at the zImage component...I expect I'll be able to do some pretty amazing things with this and a little FSO.

I think I noted a small error in the code you provided; I had to reverse the sequence of checks on monthFolder and yearFolder to get this to work, as
shown below:

set fso = CreateObject("Scripting.FileSystemObject")

if not fso.folderExists(yearFolder) then
fso.createFolder yearFolder
if not fso.folderExists(monthFolder) then
fso.createFolder monthFolder
end if
end if
response.write monthFolder
'now, you can copy anything to monthFolder

Thanks again for all of your help.

-KF


"Aaron Bertrand [MVP]" <aa***@TRASHaspfaq.com> wrote in message
news:%2***************@tk2msftngp13.phx.gbl...
<%
yearFolder = server.Mappath("/" & year(date()) & "/") & "\"
monthFolder = yearFolder & monthname(month(date())) & "\"

set fso = CreateObject("Scripting.FileSystemObject")
if not fso.folderExists(monthFolder) then
fso.createFolder monthFolder
if not fso.folderExists(yearFolder) then
fso.createFolder yearFolder
end if
end if

' now, you can copy anything to monthFolder

set fso = nothing

%>

Maybe a useful tutorial here?
http://www.aspfaq.com/2039

--
Aaron Bertrand
SQL Server MVP
http://www.aspfaq.com/


"Ken Fine" <ke*****@u.washington.edu> wrote in message
news:bt**********@nntp6.u.washington.edu...
I want my application to maintain a directory tree based on months and
years, e.g.:

2004
January
file
file
file
February
file
file
...
Anyone have some FSO code that would do something similar to the following?
Grab the current date based on the system time
If user tries to do X action and the appropriate year directory doesn't exist, create a directory named by the year (e.g. 2004)
If the appropriate month directory doesn't exist, create a
subdirectory of the appropriate year directory named by the month
Copy file (or do whatever) to the appropriate year/month directory
based on
the current system time.

Thanks in advance.

-KF



Jul 19 '05 #4

P: n/a
Naive question, but is it possible that the month subfolder can't be created
before the parent year folder is in place?

That was the assumption that led me to try switching the two around...code
worked after. But maybe I made another change without noticing...

-KF

"Aaron Bertrand [MVP]" <aa***@TRASHaspfaq.com> wrote in message
news:uw**************@TK2MSFTNGP10.phx.gbl...
I had nested them with this logic in mind: "if the month folder doesn't yet exist, then we know we have to create the month folder. We might *also*
have to create the year folder." I didn't test it thoroughly, but it
certainly seems like it should work as written. I'm not sure how you can
expect the yearFolder check to return false but the monthFolder to return
true. If the monthFolder returns true, we don't have to check if its parent exists...

--
Aaron Bertrand
SQL Server MVP
http://www.aspfaq.com/


"Ken Fine" <ke*****@u.washington.edu> wrote in message
news:#F**************@TK2MSFTNGP12.phx.gbl...
Ah, Aaron, so good, thanks so much. I already have the code running and am
madly writing millions of files to my filesystem with datetime stamps
concatinated to filenames. Soon I will be auto-categorizing photo uploads, doing file maintenance, writing dynamic pages to static instances, and

many
other cool things with the wonders of FSO.

Folks who want to play around with image management and manipulation in

the
context of CMS-ey type stuff should look at the zImage component...I

expect
I'll be able to do some pretty amazing things with this and a little FSO.
I think I noted a small error in the code you provided; I had to reverse

the
sequence of checks on monthFolder and yearFolder to get this to work, as
shown below:

set fso = CreateObject("Scripting.FileSystemObject")

if not fso.folderExists(yearFolder) then
fso.createFolder yearFolder
if not fso.folderExists(monthFolder) then
fso.createFolder monthFolder
end if
end if
response.write monthFolder
'now, you can copy anything to monthFolder

Thanks again for all of your help.

-KF


"Aaron Bertrand [MVP]" <aa***@TRASHaspfaq.com> wrote in message
news:%2***************@tk2msftngp13.phx.gbl...
<%
yearFolder = server.Mappath("/" & year(date()) & "/") & "\"
monthFolder = yearFolder & monthname(month(date())) & "\"

set fso = CreateObject("Scripting.FileSystemObject")
if not fso.folderExists(monthFolder) then
fso.createFolder monthFolder
if not fso.folderExists(yearFolder) then
fso.createFolder yearFolder
end if
end if

' now, you can copy anything to monthFolder

set fso = nothing

%>

Maybe a useful tutorial here?
http://www.aspfaq.com/2039

--
Aaron Bertrand
SQL Server MVP
http://www.aspfaq.com/


"Ken Fine" <ke*****@u.washington.edu> wrote in message
news:bt**********@nntp6.u.washington.edu...
> I want my application to maintain a directory tree based on months and > years, e.g.:
>
> 2004
> January
> file
> file
> file
> February
> file
> file
> ...
> Anyone have some FSO code that would do something similar to the
following?
> Grab the current date based on the system time
> If user tries to do X action and the appropriate year directory

doesn't > exist, create a directory named by the year (e.g. 2004)
> If the appropriate month directory doesn't exist, create a subdirectory
of
> the appropriate year directory named by the month
> Copy file (or do whatever) to the appropriate year/month directory

based on
> the current system time.
>
> Thanks in advance.
>
> -KF
>
>
>



Jul 19 '05 #5

P: n/a
Oh yeah, I did that in the wrong order. Like I said, testing wasn't
extensive. :-)

BTW, the way you have it, the month folder will only get created if the year
folder doesn't already exist. My nesting was correct, just got the order of
operations wrong.

yearFolder = server.Mappath("/" & year(date()) & "/") & "\"
monthFolder = yearFolder & monthname(month(date())) & "\"

set fso = CreateObject("Scripting.FileSystemObject")
if not fso.folderExists(monthFolder) then
if not fso.folderExists(yearFolder) then
fso.createFolder yearFolder
end if
fso.createFolder monthFolder
end if


Naive question, but is it possible that the month subfolder can't be created before the parent year folder is in place?

That was the assumption that led me to try switching the two around...code
worked after. But maybe I made another change without noticing...

-KF

"Aaron Bertrand [MVP]" <aa***@TRASHaspfaq.com> wrote in message
news:uw**************@TK2MSFTNGP10.phx.gbl...
I had nested them with this logic in mind: "if the month folder doesn't yet
exist, then we know we have to create the month folder. We might *also*
have to create the year folder." I didn't test it thoroughly, but it
certainly seems like it should work as written. I'm not sure how you can
expect the yearFolder check to return false but the monthFolder to return true. If the monthFolder returns true, we don't have to check if its

parent
exists...

--
Aaron Bertrand
SQL Server MVP
http://www.aspfaq.com/


"Ken Fine" <ke*****@u.washington.edu> wrote in message
news:#F**************@TK2MSFTNGP12.phx.gbl...
Ah, Aaron, so good, thanks so much. I already have the code running and am madly writing millions of files to my filesystem with datetime stamps
concatinated to filenames. Soon I will be auto-categorizing photo uploads, doing file maintenance, writing dynamic pages to static instances, and

many
other cool things with the wonders of FSO.

Folks who want to play around with image management and manipulation
in
the
context of CMS-ey type stuff should look at the zImage component...I

expect
I'll be able to do some pretty amazing things with this and a little FSO.
I think I noted a small error in the code you provided; I had to
reverse the
sequence of checks on monthFolder and yearFolder to get this to work,

as shown below:

set fso = CreateObject("Scripting.FileSystemObject")

if not fso.folderExists(yearFolder) then
fso.createFolder yearFolder
if not fso.folderExists(monthFolder) then
fso.createFolder monthFolder
end if
end if
response.write monthFolder
'now, you can copy anything to monthFolder

Thanks again for all of your help.

-KF


"Aaron Bertrand [MVP]" <aa***@TRASHaspfaq.com> wrote in message
news:%2***************@tk2msftngp13.phx.gbl...
> <%
> yearFolder = server.Mappath("/" & year(date()) & "/") & "\"
> monthFolder = yearFolder & monthname(month(date())) & "\"
>
> set fso = CreateObject("Scripting.FileSystemObject")
> if not fso.folderExists(monthFolder) then
> fso.createFolder monthFolder
> if not fso.folderExists(yearFolder) then
> fso.createFolder yearFolder
> end if
> end if
>
> ' now, you can copy anything to monthFolder
>
> set fso = nothing
>
> %>
>
> Maybe a useful tutorial here?
> http://www.aspfaq.com/2039
>
> --
> Aaron Bertrand
> SQL Server MVP
> http://www.aspfaq.com/
>
>
>
>
> "Ken Fine" <ke*****@u.washington.edu> wrote in message
> news:bt**********@nntp6.u.washington.edu...
> > I want my application to maintain a directory tree based on months

and > > years, e.g.:
> >
> > 2004
> > January
> > file
> > file
> > file
> > February
> > file
> > file
> > ...
> > Anyone have some FSO code that would do something similar to the
> following?
> > Grab the current date based on the system time
> > If user tries to do X action and the appropriate year directory

doesn't
> > exist, create a directory named by the year (e.g. 2004)
> > If the appropriate month directory doesn't exist, create a

subdirectory
of
> > the appropriate year directory named by the month
> > Copy file (or do whatever) to the appropriate year/month directory

based
> on
> > the current system time.
> >
> > Thanks in advance.
> >
> > -KF
> >
> >
> >
>
>



Jul 19 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.