From: Al Dunbar on 6 Jun 2010 18:48 "James Watkins" <someone(a)microsoft.com> wrote in message news:ORXo4OOBLHA.1888(a)TK2MSFTNGP05.phx.gbl... > > "Dave "Crash" Dummy" <invalid(a)invalid.invalid> wrote in message > news:cAqOn.91072$rE4.32891(a)newsfe15.iad... >> Oleg wrote: >>> Can someone tell if its possible to replace the basename of a number >>> of .jpg files in specified folder to match their date stamp? >>> file.DateCreated can see that date, but how can I actually rename the >>> files? Thanks! >> >> The script below will do what you want. I recommend using >> DateLastModified instead of DateCreated. That is what is displayed in >> Explorer. The DateCreated changes every time the file is copied. >> >> The date-time string contains illegal characters for a filename (/,:), so >> those have to be replaced. Another possible trouble spot, one that is >> not dealt with in this script, is two files having the same date-time. >> >> '=================rename.vbs================ >> set fso=CreateObject("Scripting.FileSystemObject") >> set objFolder=fso.getFolder("d:\pics") >> >> for each file in objFolder.files >> filename=LCase(file.name) >> if right(filename,4)=".jpg" then >> newname=file.dateLastModified >> newname=replace(newname,"/","-") >> newname=replace(newname,":","-") >> file.name=newname & ".jpg" >> end if >> next >> '========================================= >> -- >> Crash >> >> "Something there is that doesn't love a wall, that wants it down." >> ~ Robert Frost ~ > > The OP's question was "Can someone tell if its possible to replace the > basename of a number of .jpg files in specified folder to match their date > stamp?". Your comprehensive reply reminds me of the saying "Give a man a > fish; you have fed him for today. Teach a man to fish; and you have fed > him for a lifetime". Nice observation. The OP should now be able to eat "datestamped file" fish for the rest of his life. Not so sure that he will be able to eat "asking the intended question" fish ;-) To the OP: if you are confused by my comment, what I mean is that you probably meant to ask "How can I write a script to replace...". In the old days a question such as yours would likely get numerous responses of these varieties: "Yes, someone probably could tell you whether or not it is possible..." "Yes, it is possible..." /Al
From: Oleg on 8 Jun 2010 02:36 Crash, Many thanks, its amazing!;-) the script worked like a charm, the result looks different than what I get by using the FOR command in cmd, but its much easier to use and error-free. Great help! "Dave "Crash" Dummy" wrote: > Oleg wrote: > > Thanks, that works !:) I didnt know the code that told the script to > > actually do the job, now its clear. However, it runs into the problem > > when 2 files have the identical timestamp, then the script terminates > > with an error. Is it possible to use fso.MoveFile for the collection > > of files? So that the script first renames and moves file to the > > destination folder, then processes another. > > Pegasus' second suggestion, appending the date-time string to the > original name, is the simplest. His first suggestion, adding a numerical > suffix, can be implemented using a dictionary object. The reworked > script below does that. > > '=================rename.vbs================ > set fso=CreateObject("Scripting.FileSystemObject") > set objFolder=fso.getFolder("e:\pics") > > Set d=CreateObject("Scripting.Dictionary") > > for each file in objFolder.files > filename=LCase(file.name) > if right(filename,4)=".jpg" then > newname=file.dateLastModified > newname=replace(newname,"/","-") > newname=replace(newname,":","-") > if d.Exists(newname) then > d.Item(newname)=d.Item(newname)+1 > else > d.Add newname,1 > end if > file.name=newname & "-" & d.Item(newname) & ".jpg" > end if > next > '========================================= > -- > Crash > > "The real question is not whether machines think but whether men do." > ~ B. F. Skinner ~ > . >
From: Oleg on 8 Jun 2010 03:03 Dave, Can you explain couple of things in you script? Im trying to understand how it works. 1. You set d as Scripting Distionary - d must be there or any word or letter can be set as S.Dictionary? 2. In line if right(filename,4)=".jpg" then - what does 4 stand for? 3. Also in line d.Add newname,1 im wondering what 1 means... Thanks for your time and patience! :) "Dave "Crash" Dummy" wrote: > Oleg wrote: > > Can someone tell if its possible to replace the basename of a number > > of .jpg files in specified folder to match their date stamp? > > file.DateCreated can see that date, but how can I actually rename the > > files? Thanks! > > The script below will do what you want. I recommend using > DateLastModified instead of DateCreated. That is what is displayed in > Explorer. The DateCreated changes every time the file is copied. > > The date-time string contains illegal characters for a filename (/,:), so > those have to be replaced. Another possible trouble spot, one that is > not dealt with in this script, is two files having the same date-time. > > '=================rename.vbs================ > set fso=CreateObject("Scripting.FileSystemObject") > set objFolder=fso.getFolder("d:\pics") > > for each file in objFolder.files > filename=LCase(file.name) > if right(filename,4)=".jpg" then > newname=file.dateLastModified > newname=replace(newname,"/","-") > newname=replace(newname,":","-") > file.name=newname & ".jpg" > end if > next > '========================================= > -- > Crash > > "Something there is that doesn't love a wall, that wants it down." > ~ Robert Frost ~ > . >
From: Oleg on 8 Jun 2010 03:03 Pegasus, Adding a numerical value works better in my case, as my camera gives prety long names to the pictures, smth like Picturexxxxxxxx, if I add a date on top of that, the name would be too long, I'd like to avoid that "Pegasus [MVP]" wrote: > Moving the file before renaming it would mitigate the problem but not > eliminate it. To really eliminate it you need to expand the file name with a > numerical suffix that you keep increasing until it becomes unique. A better > alternative would be not to rename the file but to add the date stamp to the > existing file name. In this way you would not get any duplicate names at > all. > > "Oleg" <Oleg(a)discussions.microsoft.com> wrote in message > news:DA63C844-D044-437C-92FD-3C395C7E02DC(a)microsoft.com... > > Thanks, that works !:) I didnt know the code that told the script to > > actually > > do the job, now its clear. > > However, it runs into the problem when 2 files have the identical > > timestamp, > > then the script terminates with an error. > > Is it possible to use fso.MoveFile for the collection of files? So that > > the > > script first renames and moves file to the destination folder, then > > processes > > another. > > Sorry for the newby questions, im pretty new to VBScript... > > > > Oleg > > > > "Dave "Crash" Dummy" wrote: > > > >> Oleg wrote: > >> > Can someone tell if its possible to replace the basename of a number > >> > of .jpg files in specified folder to match their date stamp? > >> > file.DateCreated can see that date, but how can I actually rename the > >> > files? Thanks! > >> > >> The script below will do what you want. I recommend using > >> DateLastModified instead of DateCreated. That is what is displayed in > >> Explorer. The DateCreated changes every time the file is copied. > >> > >> The date-time string contains illegal characters for a filename (/,:), so > >> those have to be replaced. Another possible trouble spot, one that is > >> not dealt with in this script, is two files having the same date-time. > >> > >> '=================rename.vbs================ > >> set fso=CreateObject("Scripting.FileSystemObject") > >> set objFolder=fso.getFolder("d:\pics") > >> > >> for each file in objFolder.files > >> filename=LCase(file.name) > >> if right(filename,4)=".jpg" then > >> newname=file.dateLastModified > >> newname=replace(newname,"/","-") > >> newname=replace(newname,":","-") > >> file.name=newname & ".jpg" > >> end if > >> next > >> '========================================= > >> -- > >> Crash > >> > >> "Something there is that doesn't love a wall, that wants it down." > >> ~ Robert Frost ~ > >> . > >> > . >
From: Oleg on 8 Jun 2010 03:03 Sorry for the bad formulation of my question :) English is not my native lang., and still new to this forum, will try to be more specific in next posts ;) Still, I didnt get any OT replies :) "Al Dunbar" wrote: > > > "James Watkins" <someone(a)microsoft.com> wrote in message > news:ORXo4OOBLHA.1888(a)TK2MSFTNGP05.phx.gbl... > > > > "Dave "Crash" Dummy" <invalid(a)invalid.invalid> wrote in message > > news:cAqOn.91072$rE4.32891(a)newsfe15.iad... > >> Oleg wrote: > >>> Can someone tell if its possible to replace the basename of a number > >>> of .jpg files in specified folder to match their date stamp? > >>> file.DateCreated can see that date, but how can I actually rename the > >>> files? Thanks! > >> > >> The script below will do what you want. I recommend using > >> DateLastModified instead of DateCreated. That is what is displayed in > >> Explorer. The DateCreated changes every time the file is copied. > >> > >> The date-time string contains illegal characters for a filename (/,:), so > >> those have to be replaced. Another possible trouble spot, one that is > >> not dealt with in this script, is two files having the same date-time. > >> > >> '=================rename.vbs================ > >> set fso=CreateObject("Scripting.FileSystemObject") > >> set objFolder=fso.getFolder("d:\pics") > >> > >> for each file in objFolder.files > >> filename=LCase(file.name) > >> if right(filename,4)=".jpg" then > >> newname=file.dateLastModified > >> newname=replace(newname,"/","-") > >> newname=replace(newname,":","-") > >> file.name=newname & ".jpg" > >> end if > >> next > >> '========================================= > >> -- > >> Crash > >> > >> "Something there is that doesn't love a wall, that wants it down." > >> ~ Robert Frost ~ > > > > The OP's question was "Can someone tell if its possible to replace the > > basename of a number of .jpg files in specified folder to match their date > > stamp?". Your comprehensive reply reminds me of the saying "Give a man a > > fish; you have fed him for today. Teach a man to fish; and you have fed > > him for a lifetime". > > Nice observation. The OP should now be able to eat "datestamped file" fish > for the rest of his life. Not so sure that he will be able to eat "asking > the intended question" fish ;-) > > To the OP: if you are confused by my comment, what I mean is that you > probably meant to ask "How can I write a script to replace...". In the old > days a question such as yours would likely get numerous responses of these > varieties: > > "Yes, someone probably could tell you whether or not it is possible..." > "Yes, it is possible..." > > /Al > > > . >
First
|
Prev
|
Next
|
Last
Pages: 1 2 3 4 Prev: Read Text file, display output Next: VBScript & Lotus Notes |