?
Solved

Rename a file

Posted on 2006-11-15
9
Medium Priority
?
243 Views
Last Modified: 2010-04-16
Hi there,

I 'am looking for a simple way to rename a file.
In rename.cmd I have this: ren *.* SBS.*
Original file:
231-333.jpg
The result:
SBS-333.jpg
I lost 3 characters.
Is it possible with a cmd to prevent this from happening.

Erik

0
Comment
Question by:fmew
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 2
  • +1
9 Comments
 
LVL 15

Expert Comment

by:angus_young_acdc
ID: 17945884
What are you using?  C++, C# etc?  If you can let me know I might be able to help
0
 

Author Comment

by:fmew
ID: 17945973
WOW, Angus Young, my hero!

Well, Iam not a programmer, although I know some basic VB (it should be possible with VB, but I cannot do this).
At the moment I use a query in MsAccess to append characters to a filename, this works.
So the rename function in DOS will not work with this?

Erik
0
 
LVL 9

Expert Comment

by:DjDezmond
ID: 17946011
Its a batch he's using... Dont know why you getting that result though Erik.

Try using a vbscript...
--------------------------------------------------------------------------
Set FSO = CreateObject("Scripting.FilesystemObject")
Set oShell = CreateObject("Wscript.Shell")
Set objShell = CreateObject("Shell.Application")

Set objFolder = FSO.GetFolder("C:\Test")

For Each objFile in objFolder.Files
      FSO.MoveFile objFile, objFolder.Path & "\SBS" & FSO.GetFileName(ObjFile)
Next
--------------------------------------------------------------------------

This script will put 'SBS' on the beggining of every filename... You can change this by altering the following line:

FSO.MoveFile objFile, objFolder.Path & "\SBS" & FSO.GetFileName(ObjFile)

If you need to change it in anyother way and are not familiar with scripting... let us know and we can help you further
0
Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

 
LVL 19

Expert Comment

by:Limbeck
ID: 17946057
ren * sbs*  

should work, tested it
0
 
LVL 9

Expert Comment

by:DjDezmond
ID: 17946059
Ive altered the 'For Each' loop to make it abit clearer on how to change the text string...

For Each objFile in objFolder.Files
      Filename = FSO.GetFileName(ObjFile)                       '-Filename string
      FileWoutExt = Left(Filename, Len(Filename) - 4)        '-Filename without extension
      Extension = FSO.GetExtensionName(ObjFile)              '-Extension
      
<<Put one of the following lines here>>
Next

If the original file is called "1234.Doc" then these lines would change them to:
  FSO.MoveFile objFile, objFolder.Path & "\SBS" & Filename   = SBS1234.Doc
  FSO.MoveFile objFile, objFolder.Path & FileWoutExt & "\SBS" & Extension  = 1234SBS.Doc

This will happen for all files in the directory you specify here:
  Set objFolder = FSO.GetFolder("C:\Test")

Hope this helps...
0
 
LVL 19

Expert Comment

by:Limbeck
ID: 17946121
ah err didnt test it properly, it didnt work. this does

on the commandline:

for %f in (*.*)  do ren %f SBS%f
0
 

Author Comment

by:fmew
ID: 17947009
Limbeck,

This works from the commandline, but not in a batchfile.
Do I do something wrong? Or does it just dont work in a batch!
In <rename.cmd> I have:
cd\
cd C:\Test
for %f in (*.*)  do ren %f S%f

DjDezmond,
I try the VBscript later

Erik
0
 
LVL 19

Accepted Solution

by:
Limbeck earned 1000 total points
ID: 17947060
for a batch fileuse %%f instead of %f

for %%f in (*.*)  do ren %%f S%%f
0
 

Author Comment

by:fmew
ID: 17969600
the vb code is probebly ok, but I was looking for a dos batch code, so i'll  grade limbeck, course this works. I hope you agree DjDezmond!
(just for fun)! where is my hero angus, my 6 year old boy is fond about you. Playbacking you with his gitar.  

Thank you all

Erik
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
If you’re thinking to yourself “That description sounds a lot like two people doing the work that one could accomplish,” you’re not alone.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Progress

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question