Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Rename files in a folder 1

Status
Not open for further replies.

Rich96

Technical User
Oct 3, 2002
26
0
0
US
I'm needing to append to file names a static letter (let's say the letter X) Ex: TT1PP2-A0.tif --> TT1PP2-A0X.tif

I know I can use the obj.MoveFile method but not sure how to go implement it to look at a specific folder and change all files in it. Thanks. This is what I've got:


Set FldCnt = objFd1.Files
For Each fl in FldCnt
objFSO.MoveFile fl, "X.tif"
Next
Set FldCnt = Nothing
 
isnt the FileObject.Name a read/write property??
cant you just do

objFile.Name = Left(objFile.Name, Len(objFile.Name, 4)) & "X" & Right(objFile.Name, 4))

regardsm
von moyla
 
thanks mrmovie for a quick reply. i think i'm getting closer but i get an error 'Wrong number of arguments or invalid property assignment: 'Len'

is the syntax correct?
 
Left(objFile.Name, (Len(objFile.Name)- 4)) & "X" & Right(objFile.Name, 4))
 
Worked great! Thank you chmohan and mrmovie. Here is the final code.

Set FldCnt = objFd1.Files
For Each fl in FldCnt
fl.name= Left(fl.Name, (Len(fl.Name)-4)) & "X" & Right(fl.Name, 4)

msgbox fl.name

Next


 
Is the above the complete code? I get an error "Object required 'objfd1'. Forgive me just getting started
 
Here is part of the code. With all the objects.

Dim objFSO, _
objwsh, _
objFd1, _
fldPa1, _
fldCnt, _
File, _
Fl

fldPa1 = "\\Oc-ds\ABT\New Accounts\DrvLic\__Scanned"

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objwsh = CreateObject("Wscript.Shell")
Set objFd1 = objFSO.GetFolder(fldPa1)

Set FldCnt = objFd1.Files
For Each fl in FldCnt
fl.name= Left(fl.Name, (Len(fl.Name)-4)) & "X" & Right (fl.Name, 4)
Next

Set FldCnt = Nothing



Rich Bateman
American Bank of Texas
 
Can I test the file name before appending to it. I added a line to it but it keeps adding an X. Thanks


Set FldCnt = objFd1.Files

For Each fl in FldCnt
If Left(fl.name,1) <> &quot;X&quot; Then
fl.name= Left(fl.Name, (Len(fl.Name)-4)) & &quot;X&quot; & Right(fl.Name, 4)
End If
Next

Set FldCnt = Nothing


Rich Bateman
American Bank of Texas
 
no u have to use mid or substr function to check 5th character or use InStr
If InStr(fl.name,&quot;X&quot;) <>0 then
your code
 
Thanks chmohan. I used If InStr(fl.name, &quot;X&quot;) = 0 Then my code. works great.

Rich Bateman
American Bank of Texas
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top