Using cfdirectory to list a files:
Recently I was asked to create an upload tool that takes radio shows from a particular station and uploads then for archival purposes.
The first thing i needed to do was to create a form that formatted the date and grabbed the file. I had to break this into two parts:
one part used the very hand cfform cffinput container called dateselect: here is the code:
In the code above notice the mask="yyyymmdd" that formats my date and the cfparam sets the date for today.
The code above is so sweet. It controls user input so there is no mistake on date entry, additionally the reduced amount of code is applaudable. (note: the code will only work with MX 7) I found out we were using Coldfusion 6.1 so I had to change it to something else.
Next, I used a cfinput type="file" to grab the file on my computer.
After that I had to check to see what files were already there incase of collisions...here is the code:
#dircheck.name#
Now notice the above code...let me point out two really useful elements when checking for files that ar incremented and in my case I am looking for the file name that was last modified, that file will also have the highest number with oday's date. The great thing that happens next is that if the file does exist we run a mid function on the incremented value. If that value doesn't exist it is set to 00 if it is anything else, it checks the number then increments the number...here is the code:
You have submitted an Mp3 today, so we are going to add this and increment it to#EE# .
The tough part was managing the files. The file had to be named a certain way. There is a prefix and a dash, there is a date, then a two digit unique file number that looks like 00 or 01 or 02...etc.
So here is the file name break down and each file needed to follow certain naming conventions:
(prefix)-(date)(increment).mp3
rs-2006072100.mp3
This was not to difficult. I managed this by doing this:
Well maybe it was a bit difficult.
Well I hopes this help someone else who has cffile and cfdirectory difficulties. This stuff is never easy when you are doing this by yourself.
Talk soon,
Frank Tudor
www.300site.com
Recently I was asked to create an upload tool that takes radio shows from a particular station and uploads then for archival purposes.
The first thing i needed to do was to create a form that formatted the date and grabbed the file. I had to break this into two parts:
one part used the very hand cfform cffinput container called dateselect: here is the code:
In the code above notice the mask="yyyymmdd" that formats my date and the cfparam sets the date for today.
The code above is so sweet. It controls user input so there is no mistake on date entry, additionally the reduced amount of code is applaudable. (note: the code will only work with MX 7) I found out we were using Coldfusion 6.1 so I had to change it to something else.
Next, I used a cfinput type="file" to grab the file on my computer.
After that I had to check to see what files were already there incase of collisions...here is the code:
Now notice the above code...let me point out two really useful elements when checking for files that ar incremented and in my case I am looking for the file name that was last modified, that file will also have the highest number with oday's date. The great thing that happens next is that if the file does exist we run a mid function on the incremented value. If that value doesn't exist it is set to 00 if it is anything else, it checks the number then increments the number...here is the code:
You have submitted an Mp3 today, so we are going to add this and increment it to
The tough part was managing the files. The file had to be named a certain way. There is a prefix and a dash, there is a date, then a two digit unique file number that looks like 00 or 01 or 02...etc.
So here is the file name break down and each file needed to follow certain naming conventions:
(prefix)-(date)(increment).mp3
rs-2006072100.mp3
This was not to difficult. I managed this by doing this:
Well maybe it was a bit difficult.
Well I hopes this help someone else who has cffile and cfdirectory difficulties. This stuff is never easy when you are doing this by yourself.
Talk soon,
Frank Tudor
www.300site.com
