Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 55
Default Renaming folders

Greetings !

On the part of the Server that I have inherited,
there is a Tree consisting of
over 2,000 folders and sub-folders,
containing some 20,000 files in all.

Most of these folders have names such as

Transmittal Document379 040803 - Addendum 1 Rev01

where the 379 is the unique sequence number, and the
040803 is the date (3 Aug 2004)

What I want to do is "simply"
to run recursively through this entire batch,
deleting the words "Transmittal Document"

I would appreciate help on:
finding the sub-folder names
re-naming them
recursion in this context
finding the file names.

I DO know how to re-name THEM <grin


Thanks in anticipation


RClay AT haswell DOT com
  #2   Report Post  
Posted to microsoft.public.excel.programming
rog rog is offline
external usenet poster
 
Posts: 39
Default Renaming folders

Hi Robin, I posted this code yesterday to help somebody
run recursively through files. It sould give you a very
good idea of how to get what you want. To use it, you
first need to set a reference to the Microsoft Scripting
Runtime object (from Tools|Refernces menu option)

Public Sub GetFiles()
'prints out file type and path for each file in PATH and
any subdirectories
Const PATH As String = "C:\Mcskew"
Dim objFSo As New FileSystemObject
Dim objFolder As Folder
Dim rngOut As Range

Set rngOut = Range("A1")
Set objFolder = objFSo.GetFolder(PATH)

Process rngOut, objFolder

End Sub

Public Sub Process(ByRef p_rngOut As Range, ByRef
p_objFolder As Folder)

Dim objFolder As Folder
Dim objFile As File

For Each objFile In p_objFolder.Files
'loop through all files
p_rngOut.Value = objFile.Name
p_rngOut.Offset(0, 1).Value = objFile.PATH
p_rngOut.Offset(0, 2).Value = objFile.Type
Set p_rngOut = p_rngOut.Offset(1)
Next

For Each objFolder In p_objFolder.SubFolders
'loop through all folders in this directory
Process p_rngOut, objFolder
Next

End Sub

Rgds

Rog

-----Original Message-----
Greetings !

On the part of the Server that I have inherited,
there is a Tree consisting of
over 2,000 folders and sub-folders,
containing some 20,000 files in all.

Most of these folders have names such as

Transmittal Document379 040803 - Addendum 1 Rev01

where the 379 is the unique sequence number, and the
040803 is the date (3 Aug 2004)

What I want to do is "simply"
to run recursively through this entire batch,
deleting the words "Transmittal Document"

I would appreciate help on:
finding the sub-folder names
re-naming them
recursion in this context
finding the file names.

I DO know how to re-name THEM <grin


Thanks in anticipation


RClay AT haswell DOT com
.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 55
Default Renaming folders


Thank you so much -
that looks very much like what I need.

Erm... but I don't see the word "print" anywhere except in
the comment ?

i.e. where does it actually DO anything ? <grin
i.e. where do I start my "operations"
to change the foldernames (how do I do that?)
and filenames (I can do that)?


-----Original Message-----
Hi Robin, I posted this code yesterday to help somebody
run recursively through files. It sould give you a very
good idea of how to get what you want. To use it, you
first need to set a reference to the Microsoft Scripting
Runtime object (from Tools|Refernces menu option)

Public Sub GetFiles()
'prints out file type and path for each file in PATH and
any subdirectories
Const PATH As String = "C:\Mcskew"
Dim objFSo As New FileSystemObject
Dim objFolder As Folder
Dim rngOut As Range

Set rngOut = Range("A1")
Set objFolder = objFSo.GetFolder(PATH)

Process rngOut, objFolder

End Sub

Public Sub Process(ByRef p_rngOut As Range, ByRef
p_objFolder As Folder)

Dim objFolder As Folder
Dim objFile As File

For Each objFile In p_objFolder.Files
'loop through all files
p_rngOut.Value = objFile.Name
p_rngOut.Offset(0, 1).Value = objFile.PATH
p_rngOut.Offset(0, 2).Value = objFile.Type
Set p_rngOut = p_rngOut.Offset(1)
Next

For Each objFolder In p_objFolder.SubFolders
'loop through all folders in this directory
Process p_rngOut, objFolder
Next

End Sub

Rgds

Rog

-----Original Message-----
Greetings !

On the part of the Server that I have inherited,
there is a Tree consisting of
over 2,000 folders and sub-folders,
containing some 20,000 files in all.

Most of these folders have names such as

Transmittal Document379 040803 - Addendum 1 Rev01

where the 379 is the unique sequence number, and the
040803 is the date (3 Aug 2004)

What I want to do is "simply"
to run recursively through this entire batch,
deleting the words "Transmittal Document"

I would appreciate help on:
finding the sub-folder names
re-naming them
recursion in this context
finding the file names.

I DO know how to re-name THEM <grin


Thanks in anticipation


RClay AT haswell DOT com
.

.

  #4   Report Post  
Posted to microsoft.public.excel.programming
rog rog is offline
external usenet poster
 
Posts: 39
Default Renaming folders

As it stands, if you ran the Getfiles macro, it would dump
all the filenames/Path/type on the activesheet starting in
cell A1

The following will rename files and folders - you can
easily alter :

Option Explicit

Public Sub GetFiles()
'prints out file type and path for each file in PATH and
any subdirectories
Const PATH As String = "C:\Mcskew"
Dim objFSo As New FileSystemObject
Dim objFolder As Folder
Dim rngOut As Range

Set rngOut = Range("A1")
Set objFolder = objFSo.GetFolder(PATH)

Process rngOut, objFolder

End Sub

Public Sub Process(ByRef p_rngOut As Range, ByRef
p_objFolder As Folder)

Dim objFolder As Folder
Dim objFile As File

For Each objFile In p_objFolder.Files
'loop through all files
p_rngOut.Value = objFile.Name
p_rngOut.Offset(0, 1).Value = objFile.PATH
p_rngOut.Offset(0, 2).Value = objFile.Type

'rename file
If objFile.Name = "sausage.txt" Then
objFile.Name = "hello.txt"
End If
Set p_rngOut = p_rngOut.Offset(1)
Next

For Each objFolder In p_objFolder.SubFolders
'loop through all folders in this directory
'rename folder 'Danger' to 'crazy'
If objFolder.Name = "Danger" Then
objFolder.Name = "crazy"
End If
Process p_rngOut, objFolder
Next

End Sub



-----Original Message-----

Thank you so much -
that looks very much like what I need.

Erm... but I don't see the word "print" anywhere except

in
the comment ?

i.e. where does it actually DO anything ? <grin
i.e. where do I start my "operations"
to change the foldernames (how do I do that?)
and filenames (I can do that)?


-----Original Message-----
Hi Robin, I posted this code yesterday to help somebody
run recursively through files. It sould give you a very
good idea of how to get what you want. To use it, you
first need to set a reference to the Microsoft Scripting
Runtime object (from Tools|Refernces menu option)

Public Sub GetFiles()
'prints out file type and path for each file in PATH and
any subdirectories
Const PATH As String = "C:\Mcskew"
Dim objFSo As New FileSystemObject
Dim objFolder As Folder
Dim rngOut As Range

Set rngOut = Range("A1")
Set objFolder = objFSo.GetFolder(PATH)

Process rngOut, objFolder

End Sub

Public Sub Process(ByRef p_rngOut As Range, ByRef
p_objFolder As Folder)

Dim objFolder As Folder
Dim objFile As File

For Each objFile In p_objFolder.Files
'loop through all files
p_rngOut.Value = objFile.Name
p_rngOut.Offset(0, 1).Value = objFile.PATH
p_rngOut.Offset(0, 2).Value = objFile.Type
Set p_rngOut = p_rngOut.Offset(1)
Next

For Each objFolder In p_objFolder.SubFolders
'loop through all folders in this directory
Process p_rngOut, objFolder
Next

End Sub

Rgds

Rog

-----Original Message-----
Greetings !

On the part of the Server that I have inherited,
there is a Tree consisting of
over 2,000 folders and sub-folders,
containing some 20,000 files in all.

Most of these folders have names such as

Transmittal Document379 040803 - Addendum 1 Rev01

where the 379 is the unique sequence number, and the
040803 is the date (3 Aug 2004)

What I want to do is "simply"
to run recursively through this entire batch,
deleting the words "Transmittal Document"

I would appreciate help on:
finding the sub-folder names
re-naming them
recursion in this context
finding the file names.

I DO know how to re-name THEM <grin


Thanks in anticipation


RClay AT haswell DOT com
.

.

.

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 55
Default Renaming folders

The following will rename files and folders -

That seems to be what I wanted -
Thank you very much indeed!






  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 55
Default Renaming folders


Erm... sorry about this, but....

Public Sub Process(ByRef p_rngOut As Range, _
ByRef p_objFolder As Folder)


....gives a
Compile error:
User-defined type not defined


I guess it don't care for your "Folder" type -
and perhaps your "File" type later on ?


RClay AT haswell DOT com

  #7   Report Post  
Posted to microsoft.public.excel.programming
rog rog is offline
external usenet poster
 
Posts: 39
Default Renaming folders

Did you set the reference to the Microsoft Scripting
Object i mentioned?


-----Original Message-----

Erm... sorry about this, but....

Public Sub Process(ByRef p_rngOut As Range, _
ByRef p_objFolder As Folder)


....gives a
Compile error:
User-defined type not defined


I guess it don't care for your "Folder" type -
and perhaps your "File" type later on ?


RClay AT haswell DOT com

.

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
linking folders Trisha Excel Discussion (Misc queries) 0 August 25th 09 08:56 PM
Changing Folders! Philip J Smith Excel Worksheet Functions 0 December 7th 07 03:38 PM
Offline folders Stefano Excel Discussion (Misc queries) 0 January 24th 07 12:45 AM
moving folders Gary[_11_] Excel Programming 4 December 16th 03 07:29 PM
Get folders list Eugene[_5_] Excel Programming 1 December 10th 03 10:44 AM


All times are GMT +1. The time now is 05:36 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"