1. How can I use system cmd with variables?
- Posted by Dan Moyer <danielmoyer at pr??igy.net> Sep 17, 2007
- 573 views
I'm writing a small utility to rename a bunch of files in some folders, (I need to get rid of *spaces* in the file names, & the right-click rename won't do that), and I thought to use the following code, but it (naturally) bombed on the variable inside quotes...so how *would* I use a variable in this situation?
for n = 1 to length(newFileNames) do system("rename folderPathName & oldFileNames[n] newFileNames[n]", 2) end for
Dan Moyer
2. Re: How can I use system cmd with variables?
- Posted by Derek Parnell <ddparnell at bigp?nd?com> Sep 17, 2007
- 535 views
Dan Moyer wrote: > > I'm writing a small utility to rename a bunch of files in some folders, > (I need to get rid of *spaces* in the file names, & the right-click rename > won't do that), > and I thought to use the following code, but it (naturally) bombed on the > variable inside quotes...so how *would* I use a variable in this situation? > > }}} <eucode> > for n = 1 to length(newFileNames) do > system("rename folderPathName & oldFileNames[n] newFileNames[n]", 2) > end for > </eucode> {{{ system("rename " & "\" & folderPathName & oldFileNames[n] & "\"" & newFileNames[n], 2) -- Derek Parnell Melbourne, Australia Skype name: derek.j.parnell
3. Re: How can I use system cmd with variables?
- Posted by Dan Moyer <danielmoyer at p?o?igy.net> Sep 17, 2007
- 520 views
Dan Moyer wrote: > > I'm writing a small utility to rename a bunch of files in some folders, > (I need to get rid of *spaces* in the file names, & the right-click rename > won't do that), > and I thought to use the following code, but it (naturally) bombed on the > variable inside quotes...so how *would* I use a variable in this situation? > > }}} <eucode> > for n = 1 to length(newFileNames) do > system("rename folderPathName & oldFileNames[n] newFileNames[n]", 2) > end for > </eucode> {{{ > > Dan Moyer Oops, I notice now that I asked a similar question some time ago, & someone (don't remember who, sorry) provided following answer, I'll test it now.
procedure rename (sequence oldNameWithPath, sequence newNameWithoutPath) -- rename a file or directory (both names may contain spaces) system(sprintf("rename \"%s\" \"%s\"", {oldNameWithPath, newNameWithoutPath}), 2) end procedure rename (selectedFolderPathName & "\\" & cdFiles[n], newCdFileName)
Dan
4. Re: How can I use system cmd with variables?
- Posted by Derek Parnell <ddparnell at bi?p?nd.com> Sep 17, 2007
- 524 views
Derek Parnell wrote: > system("rename " & "\" & folderPathName & oldFileNames[n] & "\"" > & newFileNames[n], 2) Oops, a bit hasty. This is neater ... system("rename " & '"' & folderPathName & oldFileNames[n] & '"' & ' ' & newFileNames[n], 2) -- Derek Parnell Melbourne, Australia Skype name: derek.j.parnell
5. Re: How can I use system cmd with variables?
- Posted by Dan Moyer <danielmoyer at prodigy??et> Sep 17, 2007
- 520 views
Derek Parnell wrote: > > Dan Moyer wrote: > > > > I'm writing a small utility to rename a bunch of files in some folders, > > (I need to get rid of *spaces* in the file names, & the right-click rename > > won't do that), > > and I thought to use the following code, but it (naturally) bombed on the > > variable inside quotes...so how *would* I use a variable in this situation? > > > > }}} <eucode> > > for n = 1 to length(newFileNames) do > > system("rename folderPathName & oldFileNames[n] newFileNames[n]", 2) > > end for > > </eucode> {{{ > > system("rename " & "\" & folderPathName & oldFileNames[n] & "\"" > & newFileNames[n], 2) > > -- > Derek Parnell > Melbourne, Australia > Skype name: derek.j.parnell Sigh, thanks Derek, should'a known it was simple, will I *ever* learn??? But shouldn't it be: system("rename " & folderPathName & "\\" & oldFileNames[n] & " " & newFileNames[n], 2) ? Dan
6. Re: How can I use system cmd with variables?
- Posted by Derek Parnell <ddparnell at bigpon?.?om> Sep 17, 2007
- 536 views
Dan Moyer wrote: > But shouldn't it be: > system("rename " & folderPathName & "\\" & oldFileNames[n] & " " > & newFileNames[n], 2) I assumed that because you didn't have the "\\" that it was already appended to the end of the pathname. If not then the sprintf way is very neat. system(sprintf("rename \"%s\\%s\" %s", {folderPathName, oldFileNames[n], newFileNames[n]}) , 2) I have the quotes surrounding the 'from' name because you mentioned that it contains embedded spaces. -- Derek Parnell Melbourne, Australia Skype name: derek.j.parnell
7. Re: How can I use system cmd with variables?
- Posted by Dan Moyer <danielmoyer at pr??igy.net> Sep 17, 2007
- 531 views
Derek Parnell wrote: > > Dan Moyer wrote: > > But shouldn't it be: > > system("rename " & folderPathName & "\\" & oldFileNames[n] & " " > > & newFileNames[n], 2) > > I assumed that because you didn't have the "\\" that it was already appended > to the end of the pathname. If not then the sprintf way is very neat. Yes, I did already make it have "\\" at the end of the pathname, I forgot when I suggested the above; your second way worked *fine*, THANKS :) > > system(sprintf("rename \"%s\\%s\" %s", > {folderPathName, > oldFileNames[n], > newFileNames[n]}) > , 2) > > I have the quotes surrounding the 'from' name because you mentioned that it > contains embedded spaces. Ok, I wasn't sure why, but it sure worked fine Dan > > -- > Derek Parnell > Melbourne, Australia > Skype name: derek.j.parnell
8. Re: How can I use system cmd with variables?
- Posted by Shawn <pringle at te?hie?com> Sep 20, 2007
- 592 views
I think you asked the wrong question. system() puts a black rectangle on the screen. I would ask how do you rename files without going through system()? Unless you are coding for DOS you can use the ssl.e routines from the archive like this: include ssl.e as ssl if ssl:move_file( ssl:join( "\\", {folderPathName,oldFileNames[n]} ), ssl:join( "\\", {folderPathName,newFileNames[n]} ) ) then -- success end if Shawn Pringle
9. Re: How can I use system cmd with variables?
- Posted by Dan Moyer <danielmoyer at pro?ig?.net> Sep 21, 2007
- 526 views
Shawn, Ok, thanks, I didn't know about those routines. I haven't looked at them yet, but the example you provided suggests it will *move* and rename a file, is there one that just renames it? I'm just curious, as the system() command as elaborated by Derek worked fine for what I wanted. Dan Shawn wrote: > > > I think you asked the wrong question. system() puts a > black rectangle on the screen. I would ask how do you > rename files without going through system()? Unless you > are coding for DOS you > can use the ssl.e routines from the archive like this: > > include ssl.e as ssl > > if ssl:move_file( ssl:join( "\\", {folderPathName,oldFileNames[n]} ), > ssl:join( "\\", {folderPathName,newFileNames[n]} ) ) then > -- success > end if > > Shawn Pringle
10. Re: How can I use system cmd with variables?
- Posted by Dan Moyer <danielmoyer at pro?ig?.net> Sep 21, 2007
- 552 views
Shawn wrote: > > > I think you asked the wrong question. system() puts a > black rectangle on the screen. I would ask how do you > rename files without going through system()? Unless you > are coding for DOS you > can use the ssl.e routines from the archive like this: > > include ssl.e as ssl > > if ssl:move_file( ssl:join( "\\", {folderPathName,oldFileNames[n]} ), > ssl:join( "\\", {folderPathName,newFileNames[n]} ) ) then > -- success > end if > > Shawn Pringle Thanks again Shawn, I wondered if there wasn't a specific "rename" function in ssl.e, but I now see that the move_file function is what *is* intended to work also to rename files. And just in case anyone else didn't know where to find "ssl.e", it's under "SimpleStandardLibrary" (by Aku and others) in the archives. Dan (remembering to use "after-message-follows-response" forum protocol)
11. Re: How can I use system cmd with variables?
- Posted by Shawn <pringle at t?c?ie.com> Sep 21, 2007
- 510 views
I am not aware of any such function in any programming language. All of them provide generic functions that do one or another. The distinction is just not made in the kernel of the OSes as the actions as moving is just a generalization of renaming. In UNIX there is no rename command. People are accustomed to using 'mv' for doing either operation. Ok. I think if you do move_file( "dir1\\file1", "file2" ) it will probably also move the file to dir1, which is not what you want. With system however, the user could inject code strings. Like with SQL injection attacks. If you are curious about other renaming programs there is one available for Linux and it is distributed on the Puppy Linux CD. That version of Linux runs out of memory that is loaded from the CD. So you don't have to mess with your computer's hard drive. Shawn Pringle Dan Moyer wrote: > > Shawn, > > Ok, thanks, I didn't know about those routines. I haven't looked at them > yet, but the example you provided suggests it will *move* and rename a file, > is there one that just renames it? > > I'm just curious, as the system() command as elaborated by Derek worked fine > for what I wanted. > > Dan > > Shawn wrote: > > > > > > I think you asked the wrong question. system() puts a > > black rectangle on the screen. I would ask how do you > > rename files without going through system()? Unless you > > are coding for DOS you > > can use the ssl.e routines from the archive like this: > > > > include ssl.e as ssl > > > > if ssl:move_file( ssl:join( "\\", {folderPathName,oldFileNames[n]} ), > > ssl:join( "\\", {folderPathName,newFileNames[n]} ) ) then > > -- success > > end if > > > > Shawn Pringle