Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 34
Default Renaming all files in a directory

Hi NG

Im trying to rename/move all files in a directory using

Sub nytfors()
Set fs = Application.FileSearch
With fs
.LookIn = "C:\tb"
.Filename = "*.jpg"
End With
For i = 1 To fs.FoundFiles.Count
OldName = "C:\tb\" & fs.FoundFiles(i)
NewName = "C:\tb2\u" & i
'Debug.Print OldName, NewName
Name OldName As NewName
Next i
End Sub

but the code stops at
Name OldName As NewName

telling me its an invalid procedure call or argument.

Any ideas?

Jan


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 34
Default Renaming all files in a directory

Sorry. My mistake

OldName = "C:\tb\" & fs.FoundFiles(i)

should be

OldName = fs.FoundFiles(i)

And then it worked.

Jan



"Jan Kronsell" skrev i en
meddelelse ...
Hi NG

Im trying to rename/move all files in a directory using

Sub nytfors()
Set fs = Application.FileSearch
With fs
.LookIn = "C:\tb"
.Filename = "*.jpg"
End With
For i = 1 To fs.FoundFiles.Count
OldName = "C:\tb\" & fs.FoundFiles(i)
NewName = "C:\tb2\u" & i
'Debug.Print OldName, NewName
Name OldName As NewName
Next i
End Sub

but the code stops at
Name OldName As NewName

telling me its an invalid procedure call or argument.

Any ideas?

Jan




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Renaming all files in a directory

Jan,

Haven't tested it, but I would guess that you are not renaming, but moving
to a new directory as well.

You might need to create the directory

MkDir "C:\tb2\u"

at thestart.

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"Jan Kronsell" wrote in message
...
Hi NG

Im trying to rename/move all files in a directory using

Sub nytfors()
Set fs = Application.FileSearch
With fs
.LookIn = "C:\tb"
.Filename = "*.jpg"
End With
For i = 1 To fs.FoundFiles.Count
OldName = "C:\tb\" & fs.FoundFiles(i)
NewName = "C:\tb2\u" & i
'Debug.Print OldName, NewName
Name OldName As NewName
Next i
End Sub

but the code stops at
Name OldName As NewName

telling me its an invalid procedure call or argument.

Any ideas?

Jan




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 62
Default Renaming all files in a directory

Jan ,
According help, you need to add a .Execute on the fs object.

NickHK

"Jan Kronsell" wrote in message
...
Hi NG

Im trying to rename/move all files in a directory using

Sub nytfors()
Set fs = Application.FileSearch
With fs
.LookIn = "C:\tb"
.Filename = "*.jpg"
End With
For i = 1 To fs.FoundFiles.Count
OldName = "C:\tb\" & fs.FoundFiles(i)
NewName = "C:\tb2\u" & i
'Debug.Print OldName, NewName
Name OldName As NewName
Next i
End Sub

but the code stops at
Name OldName As NewName

telling me its an invalid procedure call or argument.

Any ideas?

Jan




  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 34
Default Renaming all files in a directory

Thnaks all, but i solved problem myself. I forgot that the fsfs.founfiles
already included the path, so when I removed the "c:\tb\" from the Oldname
variable it worked.

Jan


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
Renaming Files Bear Excel Discussion (Misc queries) 2 December 5th 05 09:02 PM
Maintain cell links when renaming directory containing multiple f Excel52 Excel Worksheet Functions 0 April 28th 05 10:54 PM
Check if directory empty OR no of files in directory. Michael Beckinsale Excel Programming 2 December 4th 03 10:12 PM
Renaming files Dana Wilson Excel Programming 2 October 29th 03 05:34 PM
Renaming Files Spammastergrand Excel Programming 5 September 19th 03 10:43 PM


All times are GMT +1. The time now is 12:06 AM.

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

About Us

"It's about Microsoft Excel"