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: cjake2299 on 17 Dec 2009 12:14 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.
From: Pegasus [MVP] on 17 Dec 2009 12:43 "cjake2299" <cjake2299(a)gmail.com> screv in news:7db38b3f-38db-4d67-8cc9-2df11aa0d080(a)f18g2000prf.googlegroups.com... > 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. 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.
From: cjake2299 on 17 Dec 2009 12:57 On Dec 17, 9:43 am, "Pegasus [MVP]" <n...(a)microsoft.com> wrote: > "cjake2299" <cjake2...(a)gmail.com> screv innews:7db38b3f-38db-4d67-8cc9-2df11aa0d080(a)f18g2000prf.googlegroups.com... > > > 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. > > 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.
From: Pegasus [MVP] on 17 Dec 2009 13:56 "cjake2299" <cjake2299(a)gmail.com> schrieb im Newsbeitrag news:4ecce8a2-19ed-4027-8780-7d28075a1c1d(a)u36g2000prn.googlegroups.com... > On Dec 17, 9:43 am, "Pegasus [MVP]" <n...(a)microsoft.com> wrote: >> "cjake2299" <cjake2...(a)gmail.com> screv >> innews:7db38b3f-38db-4d67-8cc9-2df11aa0d080(a)f18g2000prf.googlegroups.com... >> >> > 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. >> >> 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. 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.
From: Pegasus [MVP] on 17 Dec 2009 15:51
"cjake2299" <cjake2299(a)gmail.com> schrieb im Newsbeitrag news:4ecce8a2-19ed-4027-8780-7d28075a1c1d(a)u36g2000prn.googlegroups.com... > On Dec 17, 9:43 am, "Pegasus [MVP]" <n...(a)microsoft.com> wrote: >> "cjake2299" <cjake2...(a)gmail.com> screv >> innews:7db38b3f-38db-4d67-8cc9-2df11aa0d080(a)f18g2000prf.googlegroups.com... >> >> > 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. >> >> 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. 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. |