If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. |
|
|
Thread Tools | Rate Thread | Display Modes |
#1
|
|||
|
|||
Rearranging the name of files
Many years ago I used a batch file to rearrange the name of files.
Over the years I saved a bunch of files in the format mm-dd-yyyy. So they would sort chronological, I would like to change them to the yyyy-mm-dd Format. Does any one remember the batch file commands to do that? -- 2017: The year we learn to play the great game of Euchre |
Ads |
#2
|
|||
|
|||
Rearranging the name of files
On Fri, 22 Sep 2017 20:15:27 -0400, Keith Nuttle
wrote: Many years ago I used a batch file to rearrange the name of files. Over the years I saved a bunch of files in the format mm-dd-yyyy. So they would sort chronological, I would like to change them to the yyyy-mm-dd Format. If you only want to change the date format for the files then you can do this in Settings and enter date and time in the search box. Select Change date and time formats and then select yyyy-MM-dd. This will only change the date format for all files and folders but not a date format that is embedded in the file name. Does any one remember the batch file commands to do that? No! Sorry. |
#3
|
|||
|
|||
Rearranging the name of files
On 9/22/2017 9:36 PM, Monty wrote:
If you only want to change the date format for the files then you can do this in Settings and enter date and time in the search box. Select Change date and time formats and then select yyyy-MM-dd. This will only change the date format for all files and folders but not a date format that is embedded in the file name. The files have the names like 03-27-2017.pdf I want to rename them to 2017-03-27. So it has nothing to do with the OS Date format. -- 2017: The year we learn to play the great game of Euchre |
#4
|
|||
|
|||
Rearranging the name of files
On 2017-09-22 20:15, Keith Nuttle wrote:
Many years ago I used a batch file to rearrange the name of files. Over the years I saved a bunch of files in the format mm-dd-yyyy. So they would sort chronological, Huh? How does mm-dd-yyyy sort chronologically? As soon as you have more than a single year you're toast. You just realized that now? I would like to change them to the yyyy-mm-dd Format. Does any one remember the batch file commands to do that? Well, I could spend time working on it, supposing all your files have nothing but mm-dd-yyyy in their names it is pretty easy, but I'm a slow coder and I don't have the time. Use ReNamer instead: http://www.den4b.com/products Add a rule, Type=ReArrange, Delimiter=-, newOrder=$3-$2-$1 Took me 1 minute to "code" with this tool... Regards, -- ! _\|/_ Sylvain / ! (o o) Memberavid-Suzuki-Fdn/EFF/Red+Cross/SPCA/Planetary-Society oO-( )-Oo Always proofread carefully to see if you any words out. |
#5
|
|||
|
|||
Rearranging the name of files
B00ze wrote:
Keith Nuttle wrote: Many years ago I used a batch file to rearrange the name of files. Over the years I saved a bunch of files in the format mm-dd-yyyy. So they would sort chronological, Huh? How does mm-dd-yyyy sort chronologically? As soon as you have more than a single year you're toast. You just realized that now? I would like to change them to the yyyy-mm-dd Format. You split the paragraph at the wrong point. The phrase beginning with "So" goes with "I would like..." As: "I would like to change them to the yyyy-mm-dd Format so they would sort chronological." -- -bts |
#6
|
|||
|
|||
Rearranging the name of files
Beauregard T. Shagnasty wrote:
B00ze wrote: Keith Nuttle wrote: Many years ago I used a batch file to rearrange the name of files. Over the years I saved a bunch of files in the format mm-dd-yyyy. So they would sort chronological, Huh? How does mm-dd-yyyy sort chronologically? As soon as you have more than a single year you're toast. You just realized that now? I would like to change them to the yyyy-mm-dd Format. You split the paragraph at the wrong point. The phrase beginning with "So" goes with "I would like..." As: "I would like to change them to the yyyy-mm-dd Format so they would sort chronological." But Renamer is likely to be a better tool for it, than scripting. Especially if you're just juggling existing file name components. If you pick the wrong scripting language, it could be a challenge. Getting a file system object is probably pretty easy. Having a string manipulation library you can use/understand, including all escaping sequences, that's tougher. If you were to choose VBS, you might well find lots of sample scripts to use as templates, and then you can build what you need with some amount of copy/paste. You're "doing it wrong", if it seems you're inventing all the code from scratch yourself. If you select an obscure language for the job, then indeed, you could write it all yourself. Paul |
#7
|
|||
|
|||
Rearranging the name of files
Keith Nuttle wrote:
On 9/22/2017 9:36 PM, Monty wrote: If you only want to change the date format for the files then you can do this in Settings and enter date and time in the search box. Select Change date and time formats and then select yyyy-MM-dd. This will only change the date format for all files and folders but not a date format that is embedded in the file name. The files have the names like 03-27-2017.pdf I want to rename them to 2017-03-27. So it has nothing to do with the OS Date format. Not the most robust, files MUST be named mm-dd-yyyy.EXT to work. A hell of a lot easier to do in bash that ol' MS batch file @echo off :: format-name.bat SETLOCAL EnableDelayedExpansion SET target=%1 SET mask=*.* :: Command line check must have at least one arg IF '%target%' equ '' ( ECHO Error, missing required PATH argument GOTO ERROR ) :: Must not have quoted path IF !target:~0^,1!!target:~-1! equ "" ( ECHO - String is quoted ECHO Error, no quoted paths with embedded spaces, move to DIR and use '.' GOTO ERROR ) :: Path must exist IF NOT EXIST %target%\NUL ( ECHO Error cannot find target DIR '%target%' GOTO ERROR ) :: Set user specified mask IF NOT [%2]==[] SET mask=%2 :: move to target DIR PUSHD %target% :: Build rename batch file echo @echo off ~temp.bat FOR /F "usebackq tokens=1-4 delims=-." %%a IN (`dir /b %mask%`) DO ( echo rename %%a-%%b-%%c.%%d %%c-%%a-%%b.%%d ~temp.bat ) :: Rename files CALL ~temp.bat :: Clean up mess DEL ~temp.bat POPD ECHO Files renamed! GOTO CLEANUP :ERROR ECHO. ECHO Convert files named mm-dd-yyyy.EXT to yyyy-mm-yy.EXT ECHO SYNTAX: %0% PATH [MASK] ECHO PATH must be valid without trailing '\' ECHO Optional file MASK, e.g '*.pdf' else default '*.*' :CLEANUP SET target= SET mask= -- Take care, Jonathan ------------------- LITTLE WORKS STUDIO http://www.LittleWorksStudio.com |
#8
|
|||
|
|||
Rearranging the name of files
"Paul" wrote
| For Each objFile in colFiles..... ' Just save this to a .vbs file and drop a folder onto it. ' All files with names containing two "-" will be converted. ' Recursion could be added fairly easily. Dim FSO, oFol, sFol, Arg, objFile, colFiles Dim sFil, s1, s2, A1, Pt1 Set FSO = CreateObject("Scripting.FileSystemObject") Arg = WScript.Arguments(0) Set oFol = FSO.GetFolder(Arg) Set colFiles = oFol.Files For Each objFile in colFiles sFil = objFile.Name Pt1 = instrrev(sFil, ".") s1 = Left(sFil, Pt1 - 1) s2 = "." & right(sFil, len(sFil) - Pt1) A1 = Split(s1, "-") If ubound(A1) = 2 Then objFile.Name = A1(2) & "-" & A1(0) & "-" & A1(1) & s2 End If Next Set colFiles = Nothing Set oFol = Nothing Set FSO = Nothing |
#9
|
|||
|
|||
Rearranging the name of files
Mayayana wrote:
"Paul" wrote | For Each objFile in colFiles..... ' Just save this to a .vbs file and drop a folder onto it. ' All files with names containing two "-" will be converted. ' Recursion could be added fairly easily. Dim FSO, oFol, sFol, Arg, objFile, colFiles Dim sFil, s1, s2, A1, Pt1 Set FSO = CreateObject("Scripting.FileSystemObject") Arg = WScript.Arguments(0) Set oFol = FSO.GetFolder(Arg) Set colFiles = oFol.Files For Each objFile in colFiles sFil = objFile.Name Pt1 = instrrev(sFil, ".") s1 = Left(sFil, Pt1 - 1) s2 = "." & right(sFil, len(sFil) - Pt1) A1 = Split(s1, "-") If ubound(A1) = 2 Then objFile.Name = A1(2) & "-" & A1(0) & "-" & A1(1) & s2 End If Next Set colFiles = Nothing Set oFol = Nothing Set FSO = Nothing Unlike you, I don't know much about VBS. It took me somewhere around 12-15 web pages to look up enough commands to write a script. I think Renamer is about 100x faster than the process of writing a script :-) Paul |
#10
|
|||
|
|||
Rearranging the name of files
On 2017-09-23 00:08, Beauregard T. Shagnasty
wrote: B00ze wrote: Keith Nuttle wrote: Many years ago I used a batch file to rearrange the name of files. Over the years I saved a bunch of files in the format mm-dd-yyyy. So they would sort chronological, Huh? How does mm-dd-yyyy sort chronologically? As soon as you have more than a single year you're toast. You just realized that now? I would like to change them to the yyyy-mm-dd Format. You split the paragraph at the wrong point. The phrase beginning with "So" goes with "I would like..." As: "I would like to change them to the yyyy-mm-dd Format so they would sort chronological." Ohhhh, I did! I'm sorry! My bad! -- ! _\|/_ Sylvain / ! (o o) Memberavid-Suzuki-Fdn/EFF/Red+Cross/SPCA/Planetary-Society oO-( )-Oo "Au contraire, mon capitaine! HEEE'S BAAAACK!!!" -Q |
#11
|
|||
|
|||
Rearranging the name of files
"Paul" wrote
| It took me somewhere around 12-15 web pages to look | up enough commands to write a script. I think Renamer | is about 100x faster than the process of writing a script :-) | Maybe, for people who don't write scripts. I'm surprised that with your curiosity and expertise you've never got involved with programming. There are utility programs to do many of these things, but scripts are far more flexible for custom operations. I first got intrigued reading Windows 98 Annoyances. The author had a short chapter on VBScript. I tried out some message box scripts. It was a revelation. I realized that programming/scripting would allow me to work on the other side of the screen. I didn't have to settle for clicking buttons. I could design the functionality that happens when the button is clicked. That's very satisfying. A computer goes from being a toolbox to being a whole workshop. |
#12
|
|||
|
|||
Rearranging the name of files
Mayayana wrote:
"Paul" wrote | It took me somewhere around 12-15 web pages to look | up enough commands to write a script. I think Renamer | is about 100x faster than the process of writing a script :-) | Maybe, for people who don't write scripts. I'm surprised that with your curiosity and expertise you've never got involved with programming. There are utility programs to do many of these things, but scripts are far more flexible for custom operations. I first got intrigued reading Windows 98 Annoyances. The author had a short chapter on VBScript. I tried out some message box scripts. It was a revelation. I realized that programming/scripting would allow me to work on the other side of the screen. I didn't have to settle for clicking buttons. I could design the functionality that happens when the button is clicked. That's very satisfying. A computer goes from being a toolbox to being a whole workshop. I'm a hardware guy, so by definition I "can't be writing software" :-) Our firmware, software, and scripting exercises, had to remain a secret. They weren't prominently displayed on any month-end progress reports. And not once, do I remember any hardware managers trying to design a training track for the team, so we were all using the same tools. That's what I mean by "secret", in that management didn't want to expose how we were getting things done. Today, for example, you might want them all to be trained in PERL or something. (It's not the best choice, but it is a pretty common skill amongst hardware people.) One project I worked on, I sat down with another engineer, and we made a list of all the languages we knew. The only thing the two of us had in common was... Fortran :-) Well, puke. But Fortran it was, and we wrote thousands of lines of Fortran, just so we could pass the test vector generator back and forth and add stuff to it. It would have been madness, to use Notepad to make a 185000 line file, with a couple hundred characters per line, which is why the Fortran generated that file for us. The Fortran was succinct, we could add comments to the Fortran source (as comments aren't allowed in a Test Vector file). That's what happens when you have "secret" skills. Chaos. As far as the month end report was concerned, those test vectors just "wrote themselves" somehow. Magic. When you work scatter-shot like that, you never get good at anything. You're writing bad C code one day. You're working on Fortran another day. (I've also written Pascal code.) Being barely familiar with a whole bunch of stuff, isn't really all that useful. If you do chip or FPGA design, you're working in Verilog or VHDL (I've taken courses). But only if those are your "daily diet" will you get good at them. I used to have to review the Verilog code of one of my team members, to debug his stuff and make it work, because he was an "FPGA designer in training". So even if I "wasn't an FPGA design", I was still an FPGA designer :-) Just never getting good at it. Paul |
#13
|
|||
|
|||
Rearranging the name of files
On 2017-09-23 23:12, Mayayana wrote:
"Paul" wrote | It took me somewhere around 12-15 web pages to look | up enough commands to write a script. I think Renamer | is about 100x faster than the process of writing a script :-) | Maybe, for people who don't write scripts. You should have a look at that ReNamer tool, you do "program" it, i.e. you create a series of steps you need, in order to rename files. But it's so much faster than having to code a VBScript. The OP's rename operation was very simple, so we could all do it (I would've done it with a FOR loop in batch rather than VB, because I wrote only about 3 VB programs ever). But you can do some very complicated stuff with ReNamer. Think of it as a prototyping tool; they are quite useful, only this time you don't need to code it afterwards because you're all done... Best Regards, -- ! _\|/_ Sylvain / ! (o o) Memberavid-Suzuki-Fdn/EFF/Red+Cross/SPCA/Planetary-Society oO-( )-Oo Very funny Scotty! Now beam up my clothes! |
#14
|
|||
|
|||
Rearranging the name of files
"B00ze" wrote
| Maybe, for people who don't write scripts. | | You should have a look at that ReNamer tool, you do "program" it, i.e. | you create a series of steps you need, in order to rename files. But | it's so much faster than having to code a VBScript. It took me a couple of minutes to write the script. And it wouldn't be hard to add any degree of customization, like only renaming files from 2006 in folders with specific names. But I can see your point. If someone is not experienced with programming or scripting then doing such a job would require a lot of research and testing. Actually part of the reason I do so much scripting is because it's so quick and simple. Some things need to be done as compiled software. But many things can be done more easily as scripts or HTAs. |
Thread Tools | |
Display Modes | Rate This Thread |
|
|