Solved

Rename a file

Posted on 2006-11-15
9
241 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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 250 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

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

In this post we will learn different types of Android Layout and some basics of an Android App.
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
Six Sigma Control Plans

696 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