Rename file to folder name
Forum rules
Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Rename file to folder name
Hey everyone pretty new to this scripting thing so I thought I'd ask to see if there is quick answer (is there ever though?) Anyway I have a bunch of folders each with only 1 file in them. I want to rename the files to same name of folder they are contained in.Ex. 1234one.doc -> 12341234.docI have about 1500 folders/files that I need to do this to. Any help would be much appreciated. Thanks
Rename file to folder name
Hey everyone pretty new to this scripting thing so I thought I'd ask to see if there is quick answer (is there ever though?) Anyway I have a bunch of folders each with only 1 file in them. I want to rename the files to same name of folder they are contained in.Ex. 1234one.doc -> 12341234.docI have about 1500 folders/files that I need to do this to. Any help would be much appreciated. Thanks
Rename file to folder name
Sure... typing off the top of my head to the syntax may not be quite right. Assuming your folders are all contained in D:Folders..
Set fso = createobject("Scripting.FileSystemObject")
Set root = fso.getfolder("D:folder")
for each folder in root.subfolders
foldername = folder.name
for each file in folder.files
file.name = foldername
next
next
Something like that. That won't maintain the filename extension, but you could grab it
ext = right(file.name,4)
file.name = foldername & ext
Something like that. Not sure exactly what you want to achieve, but hopefully this is a starter.
Set fso = createobject("Scripting.FileSystemObject")
Set root = fso.getfolder("D:folder")
for each folder in root.subfolders
foldername = folder.name
for each file in folder.files
file.name = foldername
next
next
Something like that. That won't maintain the filename extension, but you could grab it
ext = right(file.name,4)
file.name = foldername & ext
Something like that. Not sure exactly what you want to achieve, but hopefully this is a starter.
Rename file to folder name
Probably not . I'm actually sure it's easier to do in PowerShell - possibly a one-liner - but in this case I think the VBScript is pretty clear to read, and I'm glad it did the job.