473,406 Members | 2,217 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,406 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 3319
<%
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.