Solved

Rename a file

Posted on 2006-11-15
9
237 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
  • 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
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

ScreenConnect 6.0 Free Trial

At ScreenConnect, partner feedback doesn't fall on deaf ears. We collected partner suggestions off of their virtual wish list and transformed them into one game-changing release: ScreenConnect 6.0. Explore all of the extras and enhancements for yourself!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
word0 challenge 4 68
tidtcpserver connection lost handle 2 83
Windows Service to Receive TCP Packets 4 145
index Out OF Range Exception error 4 61
Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
A short article about problems I had with the new location API and permissions in Marshmallow
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
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…

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