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.
"cjake2299" <cjak...@gmail.com> screv in
news:7db38b3f-38db-4d67...@f18g2000prf.googlegroups.com...
There are numerous free bulk rename utilities that will perform exactly this
task. Just put the words "windows bulk rename" into a Google search box. If
you prefer to roll your own then the File System Object has the appropriate
methods to tackle the job. Let's see what you have so far so that someone
can help you complete the script.
Thanks for the prompt reply. I have already begun the process using
the following script (modified from another post):
const strSourceDir = "C:\ProductImages"
Set objWMIService = GetObject("winmgmts:\\.\root\cimv2")
Set colFiles = objWMIService.ExecQuery _
("ASSOCIATORS OF {Win32_Directory.Name='" & strSourceDir _
& "'} Where ResultClass = CIM_DataFile")
For Each objFile In colFiles
p = InStr(objFile.FileName, "_")
if p > 2 Then
strName = Left(objFile.FileName, p-1) & "."
strNewName = objFile.Drive & objFile.Path _
& strName & objFile.extension
errResult = objFile.Rename(strNewName)
end if
Next
It did not return a count of the objects, but I was able to get that
information anyways.
"cjake2299" <cjak...@gmail.com> schrieb im Newsbeitrag
news:4ecce8a2-19ed-4027...@u36g2000prn.googlegroups.com...
If you need to process *lots* of files (your words) then WMI is the perfect
method to slow things down to a snail's pace. The File System Object runs
circles around WMI and can easily do this particular job.
"cjake2299" <cjak...@gmail.com> schrieb im Newsbeitrag
news:4ecce8a2-19ed-4027...@u36g2000prn.googlegroups.com...
To satisfy my own curiosity I ran three quick tests. Each test script read
the names of 10,000 files, located in a single folder, into an array. To
avoid disk caching effects I used three separate folders and rebooted the
machine before commencing the test. Here are the methods I used and the test
results:
Method a): Use the FSO folder.files method. Time taken = 8.6 seconds.
Method b): Shell out to the command processor to invoke the command "dir /b
> dir.txt", then read dir.txt into an array using the FSO ReadAll method.
Time taken = 0.7 seconds. This is a very fast approach but not popular with
purists because it is a hybrid solution.
Method c): Use your own WMI program. Time taken: 450 seconds. This is
typical: WMI programs tend to run at least 40 times slower than their FSO
equivalents.
I rest my case about WMI.
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.
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","")
[ "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
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
--
Crash
"When you get to a fork in the road, take it."
~ Yogi Berra ~
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.
> > 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, methinks:
file.name = replace(file.name, "_STD", "_stdTMPtmp")
file.name = replace(file.name, "_stdTMPtmp", "_std")
> This will:
> dname=replace(file.path,"_STD","_std")
> file.move dname
>
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)