Prev: Starting a 64bit program from a 32bit .HTA?
Next: Copy file from one directory to a new directory, using excel spreadsheet as reference for items to be copied
From: "Dave "Crash" Dummy" on 17 Dec 2009 21:52 cjake2299 wrote: > Greetings all- > > I have a directory that contains image files (lots of them) that all > end with "_STD.jpg". I need to remove the "_STD" portion of all the > file names, as well as return a count of all files processed. Any > help would be much appreciated. Maybe I'm missing something, but wouldn't this work? Set fso = CreateObject("Scripting.FileSystemObject") set fldr=fso.getFolder("d:\directory") filecount=0 for each file in fldr.files if instr(ucase(file.name),"_STD.JPG") then dname=replace(file.path,"_STD","") file.move dname filecount=filecount+1 end if next -- Crash Committed to the search for intraterrestrial intelligence.
From: Paul Randall on 18 Dec 2009 00:54 "Dave "Crash" Dummy" <invalid(a)invalid.invalid> wrote in message news:umtye04fKHA.2160(a)TK2MSFTNGP02.phx.gbl... > cjake2299 wrote: >> Greetings all- >> >> I have a directory that contains image files (lots of them) that all >> end with "_STD.jpg". I need to remove the "_STD" portion of all the >> file names, as well as return a count of all files processed. Any >> help would be much appreciated. > > Maybe I'm missing something, but wouldn't this work? > > Set fso = CreateObject("Scripting.FileSystemObject") > set fldr=fso.getFolder("d:\directory") > filecount=0 > for each file in fldr.files > if instr(ucase(file.name),"_STD.JPG") then > dname=replace(file.path,"_STD","") > file.move dname > filecount=filecount+1 > end if > next The name property of a FSO file object has both read and write capabilities, doesn't it? Maybe omething like the following for changing the name? file.name = replace(file.name, "_STD","")
From: Stefan Kanthak on 18 Dec 2009 05:40 "Paul Randall" <paulr901(a)cableone.net> wrote: > > "Dave "Crash" Dummy" <invalid(a)invalid.invalid> wrote in message > news:umtye04fKHA.2160(a)TK2MSFTNGP02.phx.gbl... >> cjake2299 wrote: >>> Greetings all- >>> >>> I have a directory that contains image files (lots of them) that all >>> end with "_STD.jpg". I need to remove the "_STD" portion of all the >>> file names, as well as return a count of all files processed. Any >>> help would be much appreciated. >> >> Maybe I'm missing something, but wouldn't this work? [ "bloated" VBScript ] Why not a simple *.CMD? ChDir /D "<directory>" For %! In (*_STD.jpg) Do Rename "%!" "%!:_STD=" The count is left as exercise for the reader. Stefan
From: "Dave "Crash" Dummy" on 18 Dec 2009 09:54 Paul Randall wrote: > "Dave "Crash" Dummy" <invalid(a)invalid.invalid> wrote in message > news:umtye04fKHA.2160(a)TK2MSFTNGP02.phx.gbl... >> cjake2299 wrote: >>> Greetings all- >>> >>> I have a directory that contains image files (lots of them) that >>> all end with "_STD.jpg". I need to remove the "_STD" portion of >>> all the file names, as well as return a count of all files >>> processed. Any help would be much appreciated. >> Maybe I'm missing something, but wouldn't this work? >> >> Set fso = CreateObject("Scripting.FileSystemObject") set >> fldr=fso.getFolder("d:\directory") filecount=0 for each file in >> fldr.files if instr(ucase(file.name),"_STD.JPG") then >> dname=replace(file.path,"_STD","") file.move dname >> filecount=filecount+1 end if next > > The name property of a FSO file object has both read and write > capabilities, doesn't it? Maybe omething like the following for > changing the name? file.name = replace(file.name, "_STD","") Yes, it would. I adopted my script from another application, and there was some reason (which I forget) that I couldn't do it directly. The two lines dname=replace(file.path,"_STD","") file.move dname could be replaced with file.name = replace(file.name, "_STD","") -- Crash "When you get to a fork in the road, take it." ~ Yogi Berra ~
From: "Dave "Crash" Dummy" on 18 Dec 2009 10:18
> I adopted my script from another application, and there > was some reason (which I forget) that I couldn't do it directly. Ah! Now I remember! I didn't want to change the name, exactly, I wanted to change the case. I can't do that directly because VBS doesn't distinguish case in file names. For example, if I try to change "_STD" to "_std," This won't work: file.name = replace(file.name, "_STD","_std") This will: dname=replace(file.path,"_STD","_std") file.move dname -- Crash Life is short. Eat dessert first. |