473,245 Members | 1,462 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,245 software developers and data experts.

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

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
5 3314
<%
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: Jason Kratz | last post by:
OK. I've search on google groups and around the web for this and I haven't found an answer. I'm a Python newbie and have what I assume is a basic question. os.listdir takes a pathname as an arg...
1
by: Lee Holsenbeck | last post by:
hi, i am reading the directory structure into a treeview. when i select a new drive and do not have access to an existing folder; i get an acess denied - System.UnauthorizedAccessException...
9
by: beguigne | last post by:
Below is a snippet of a crude date picking routine for a form. I am a novice at this so, I am hitting my head at why when I select the day, the onChange event gives me a blank. What am I missing?...
8
by: Steven Scaife | last post by:
Hello I am creating a reporting system using SQL Server 2000 and ASP, I have created 4 pages that display the results i want, however the reports take an average of 20 mins to run and i have...
23
by: sandy | last post by:
I need (okay, I want) to make a dynamic array of my class 'Directory', within my class Directory (Can you already smell disaster?) Each Directory can have subdirectories so I thought to put these...
1
by: Rinaldo | last post by:
Hi, I have a problem to get the directory. I've tryed: public void WriteWeb(DirectoryInfo directory) {
0
by: Ravi Kumar | last post by:
hi :) I was trying to develop a custom mod_python based web-site, just today. the problem I got though i liked the mod_python's feature of mapping and calling functions in python script by...
8
by: Cirene | last post by:
I have 1 master page in the root of my website that I would like to share with all pages, even those in my /admin and /client directories. But when pages in the subdir's are viewed the img, css,...
3
by: malcsman | last post by:
Hi there, I think it's best to explain things first.. (it's a sermons archive) I manage a static page which I'd like to automate. This page is an archive that lists mp3s and their notes(pdf) as...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.