Connecting Tech Pros Worldwide Forums | Help | Site Map

Change folders name using coldfusion scripts like cffile, read etc

Newbie
 
Join Date: Sep 2008
Posts: 20
#1: Sep 30 '08
I would like to change all my sub folders name within a main folder, how do I do that???
like: -
app1
amm1
ann1

to
app1pp
amm1pp
ann1pp

using cffile / read /write etc

(I am new to coldfusion scrtpts)

acoder's Avatar
Site Moderator
 
Join Date: Nov 2006
Location: UK
Posts: 14,581
#2: Sep 30 '08

re: Change folders name using coldfusion scripts like cffile, read etc


The first thing to do is check the Coldfusion documentation for cffile on the Adobe website. The action should be set to "rename".

If you get stuck, post back with the code that you tried.
Newbie
 
Join Date: Sep 2008
Posts: 20
#3: Oct 1 '08

re: Change folders name using coldfusion scripts like cffile, read etc


rename is to change name of file??? or name of folder

mainfolder/
app1
amm1
ann1

and inside this main folder there are also files
show.cfm
view.cfm

1. Folder name -- How do I read the folder name without the file name in a directory??

Current, I am using <cfdirectory directory="#ExpandPath( '..\..\..\..\0addResume\#aa1_addresumefirst#\' )#" action="list" name="currentDir"> to read the directory. But if I want to read the folder name with showing the file name

=====I would like to read all folder name only

Thanks
acoder's Avatar
Site Moderator
 
Join Date: Nov 2006
Location: UK
Posts: 14,581
#4: Oct 1 '08

re: Change folders name using coldfusion scripts like cffile, read etc


Sorry, I thought you wanted to rename files (I guess I didn't read carefully).

Use <cfdirectory action="rename" ...> to rename a directory. If you don't know all the names of the directories, and you want to list only directories, loop over the query returned by cfdirectory and check the type attribute. If it's "DIR", it's a directory.
Newbie
 
Join Date: Sep 2008
Posts: 20
#5: Oct 2 '08

re: Change folders name using coldfusion scripts like cffile, read etc


I have done it as follows without the cfdirectory code as

==============================

Expand|Select|Wrap|Line Numbers
  1. <cfdirectory directory="#ExpandPath( '..\..\..\..\0addResume\from word to html2\' )#" action="list" name="rs">
  2.  
  3.   <cfloop query="rs">
  4.  
  5. <cfoutput> 
  6. <cfif rs.type IS "dir">
  7. #rs.name#
  8. <cffile action="rename" source="#dd##rs.name#" destination="#dd##rs.name#_pp">
  9. </cfif>
  10. <p>
  11. </cfoutput>
  12.  
============== it is running fine ======

If I want to use cfdirectory, how do I do it??

Expand|Select|Wrap|Line Numbers
  1. <cffile action="rename" source="#dd##rs.name#" destination="#dd##rs.name#_pp" attributes="normal">
  2. or
  3. <cfdirectory action="rename" source="#dd##rs.name#" destination="#dd##rs.name#_xxx" attributes="directory">
  4.  
it gives an error:-
Attribute validation error for the CFDIRECTORY tag.
When the value of the ACTION attribute is RENAME, the tag requires the attribute(s): DIRECTORY,NEWDIRECTORY.
acoder's Avatar
Site Moderator
 
Join Date: Nov 2006
Location: UK
Posts: 14,581
#6: Oct 2 '08

re: Change folders name using coldfusion scripts like cffile, read etc


Instead of source and destination attributes, you need to use directory and newDirectory when using cfdirectory.

PS. please use code tags when posting code. Thanks.
Reply