From: ekkehard.horner on
Dave "Crash" Dummy schrieb:
> ekkehard.horner wrote:
>> Dave "Crash" Dummy schrieb: [...]
>>> There is no "rename" function in VBScript, but you can perform the
>>> action by using the "Move" or "FileMove" methods.
>> [...] Straight from the VBScript Docs:
>>
>> Name Property (FileSystemObject) Sets or returns the name of a
>> specified file or folder. Read/write. object.Name [= newname] object:
>> Required. Always the name of a File or Folder object.
>
> Yes, that will work in this case. Just replace the line
> file.move left(file.path, len(file.path)-5)
> with
> file.name= left(file.name, len(file.name)-5)
>
> I got in the habit of using "file.move" instead of "file.name" when what
> I wanted to change was the case, not the name or extension.
>
> This won't work.
> file.name= lcase(file.name)
> This will.
> file.move file.path, folder.path & "\" & lcase(file.name)
>
You are right. Thanks for pointing out the aspect of case I wasn't
aware of.

From: Al Dunbar on


"Dave "Crash" Dummy" <invalid(a)invalid.invalid> wrote in message
news:m2ubo.21209$1v3.1427(a)newsfe20.iad...
> PAkerly wrote:
>> Hello, How would I rename files with an extension line .pdf.mbin to just
>> .pdf
>>
>> so I want: myfile.pdf.mbin to be: myfile.pdf
>
> There is no "rename" function in VBScript, but you can perform the
> action by using the "Move" or "FileMove" methods. The script below will
> do what you ask. Just replace the example "d:\directory" with the path
> of interest.
>
> ---------------------renamer.vbs-------------------------
> set fso=CreateObject("Scripting.FileSystemObject")
> set folder=fso.getFolder("d:\directory")
> for each file in folder.files
> if right(file.name,5)=".mbin" then
> file.move left(file.path, len(file.path)-5)
> end if
> next
> -------------------------------------------------------------

Two caveats... supposing the folder contains abcd.mbin, zxcv.pdf.mbin, and
zxcv.pdf: the first file will be renamed as abcd (not what OP asked for),
and the second will not successfully be renamed, as a file named zxcv.pdf
already exists. Perhaps one of those cases where the ERR object should be
used...

/Al


From: Todd Vargo on
Dave "Crash" Dummy wrote:
> PAkerly wrote:
>> Hello, How would I rename files with an extension line .pdf.mbin to
>> just .pdf
>>
>> so I want: myfile.pdf.mbin to be: myfile.pdf
>
> There is no "rename" function in VBScript, but you can perform the
> action by using the "Move" or "FileMove" methods. The script below will
> do what you ask. Just replace the example "d:\directory" with the path
> of interest.
>
> ---------------------renamer.vbs-------------------------
> set fso=CreateObject("Scripting.FileSystemObject")
> set folder=fso.getFolder("d:\directory")
> for each file in folder.files
> if right(file.name,5)=".mbin" then
> file.move left(file.path, len(file.path)-5)

Two lines above should be this...

if lcase(right(file.name,9))=".pdf.mbin" then
file.move left(file.path, len(file.path)-9)


> end if
> next
> -------------------------------------------------------------

From: "Dave "Crash" Dummy" on
Todd Vargo wrote:
> Dave "Crash" Dummy wrote:
>> PAkerly wrote:
>>> Hello, How would I rename files with an extension line .pdf.mbin to
>>> just .pdf
>>>
>>> so I want: myfile.pdf.mbin to be: myfile.pdf
>>
>> There is no "rename" function in VBScript, but you can perform the
>> action by using the "Move" or "FileMove" methods. The script below will
>> do what you ask. Just replace the example "d:\directory" with the path
>> of interest.
>>
>> ---------------------renamer.vbs-------------------------
>> set fso=CreateObject("Scripting.FileSystemObject")
>> set folder=fso.getFolder("d:\directory")
>> for each file in folder.files
>> if right(file.name,5)=".mbin" then
>> file.move left(file.path, len(file.path)-5)
>
> Two lines above should be this...
>
> if lcase(right(file.name,9))=".pdf.mbin" then
> file.move left(file.path, len(file.path)-9)

No, that would leave the file with no extension. The conditional
statement could be revised as you suggest, but the command
would still be

file.move left(file.path, len(file.path)-5)
--
Crash

Ignorance is curable. Stupidity is refusing treatment.
From: Todd Vargo on
Dave "Crash" Dummy wrote:
> Todd Vargo wrote:
>> Dave "Crash" Dummy wrote:
>>> PAkerly wrote:
>>>> Hello, How would I rename files with an extension line .pdf.mbin to
>>>> just .pdf
>>>>
>>>> so I want: myfile.pdf.mbin to be: myfile.pdf
>>>
>>> There is no "rename" function in VBScript, but you can perform the
>>> action by using the "Move" or "FileMove" methods. The script below will
>>> do what you ask. Just replace the example "d:\directory" with the path
>>> of interest.
>>>
>>> ---------------------renamer.vbs-------------------------
>>> set fso=CreateObject("Scripting.FileSystemObject")
>>> set folder=fso.getFolder("d:\directory")
>>> for each file in folder.files
>>> if right(file.name,5)=".mbin" then
>>> file.move left(file.path, len(file.path)-5)
>>
>> Two lines above should be this...
>>
>> if lcase(right(file.name,9))=".pdf.mbin" then
>> file.move left(file.path, len(file.path)-9)
>
> No, that would leave the file with no extension. The conditional
> statement could be revised as you suggest, but the command
> would still be
>
> file.move left(file.path, len(file.path)-5)

Right on. Thinking I forgot to change the 5 to a 9, I changed the second
line just before posting. Duh!

This exemplifies why posting to the group is more sensible than privately
via email. Others not only learn from the help, but others also have an
opportunity to catch mistakes. Thanks Crash.

--
Todd Vargo

(Post questions to group only. Remove "z" to email personal messages)