Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Rename a file

Posted on 2006-11-15
9
Medium Priority
?
244 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
Technology Partners: 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 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

Tech or Treat! - Giveaway

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

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

A short article about problems I had with the new location API and permissions in Marshmallow
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
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 …
Simple Linear Regression

610 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