473,387 Members | 1,516 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Remove random strings from file name that begin with @ and end at .ext

I need to rename files from filename@f{|56rdfyhf.txt to filename.txt. All file names contain a random string that begin with @ with random string up to .ext
Thank for any help.
Janet
Dec 9 '14 #1
4 1164
twinnyfo
3,653 Expert Mod 2GB
Janet,

If I understand you correctly, here is the situation you have:

Expand|Select|Wrap|Line Numbers
  1. Original Filename            Renamed to
  2. filename@f{|56rdfyhf.txt     filename.txt
  3. AnotherFile.doc              [Unchanged]
  4. WorkFile@abc123.xlsx         WorkFile.xlsx
I just want to make sure I understand before we try to begin.

Some additional questions: What happens if the newly renamed file already exists? Do you over-write or add a sequential number?

The basics of your solution will be to cycle through all your files, determine whether they need to be renamed, if they do, change the name, if not, leave it alone.

Because of some of the additional questions I have asked, this may end up being a little involved than what I initially imagined, but I am sure that we can point you in the right direction of a solution.
Dec 9 '14 #2
No duplicate files will be created
Dec 9 '14 #3
You have it right! There won't be any files in the folder that are named correctly. Thanks for your help!
Janet
Dec 9 '14 #4
twinnyfo
3,653 Expert Mod 2GB
Good! That actually makes some of this a bit easier.

I will try to guide you through a generic process that you can apply to any folder. I will not write all the code, because I want you to try to work through some of this yourself. I will help you through any trouble spots. We prefer to work this way on this forum, because we want our posters to gain a better understanding of the process and the programming language than just "providing the solution". hopefully you will have a solution, but also you will understand it.

So here is a skeleton of what your Function will look like:

Expand|Select|Wrap|Line Numbers
  1. Public Function RenameFiles(strFolder as String)
  2. On Error GoTo EH
  3.     'Declare the variables you will use
  4.     'You will probably need at least two strings:
  5.     'One for the name of the old File, one for the new
  6.     'You will probably need some sort of Integer pointer...
  7.  
  8.     'The Dir() function will get a list of files, one at a time
  9.     'When you set a variable equal to Dir([FolderName]) you
  10.     'will get the name of the first file in the folder
  11.     'The next time you use Dir()--no arguments--you will get
  12.     'the next file name.  When Dir() = "", you have run out
  13.     'of files.  Use this to your advantage
  14.  
  15.     'So....... Find the first file name here:
  16.  
  17.     [Your Code]
  18.  
  19.     'You will want to loop through records at this point
  20.     'to determine if we have run out of files
  21.  
  22.     'Find out if your File Name has "@" in it
  23.     'An effective Function to use is Instr()
  24.     'Instr([FileName], "@") will return the number of
  25.     'character in the string the search element is found
  26.     'That function returns 0 if it is not found
  27.  
  28.     'So, if you find the "@", then you also have to find
  29.     'The extension (usually 3-4 characters, but may be more)
  30.     'Several ways to do that--you could use Instr() again
  31.     'as long as there are no more "."s in the file name
  32.  
  33.     'So, if you determine that the file name is 
  34.     '"filename@f{|56rdfyhf.txt" and the "@" is character 9
  35.     'and the extension is ".txt" then you must generate
  36.     'the new file name to be:  "filename.txt"
  37.  
  38.     'Thus, Rename the file (since it is not being "opened"
  39.     'This should be relatively easy:
  40.  
  41.     Name [OldFileName] As [NewFileName]
  42.  
  43.     'Now, you need to find the next file in the folder
  44.     'Here is where you will loop back through your code
  45.  
  46.  
  47.     Exit Function
  48. EH:
  49.     MsgBox "There was an error renaming the Files!  Error:  " & _
  50.         Err.Desription 
  51.     Exit Function
  52. End Function
So, is this a solution? Well, not yet. But, I will be glad to continue to work you through understanding this problem. Hopefully, this will not take real long. I am glad to assist every step of the way.
Dec 9 '14 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Jamie A. Landers | last post by:
I have a macro that runs to export a report. It dumps a report on the server in RTF format. Here's the problem that I am having. I would like for the report to have a custom file name daily, like...
17
by: Joe Laughlin | last post by:
I've not used C much before, so I don't know how robust or good this code is. I'd appreciate any feedback or criticisms anyone has! Thanks, Joe #include <stdio.h> #include <string.h>
3
by: Manuel | last post by:
I've playing around with multi-threading applications lately. The main problem I have is that when I create a file/table/whatever I need a unique name. The only way I could come up with, is asking...
2
by: Nikolay Petrov | last post by:
I am quite sure that i've seen an vb function or framework method which gives random temp file name to use in app, but i can't remember where it was exactly. Can someone help? TIA
2
by: Andy.I | last post by:
Hi I have a small aplication that stores data in a random access file. I'm able to modify records, and add new records. But how can I delete a certain record and remove it enirely from the file?...
6
by: Mike P | last post by:
I am generating 12 random strings and my code works fine when I step through, but when I then let it run without stepping through and populate a listbox with the array I am building, I get the same...
185
by: jacob navia | last post by:
Hi We are rewriting the libc for the 64 bit version of lcc-win and we have added a new field in the FILE structure: char *FileName; fopen() will save the file name and an accessor function will...
2
by: Angela Nicholson | last post by:
I am new to python converting from C++ so this may seems like a simple solution. I have a script that when a drive and folder name is input, a field is added to all shapefiles within the folder. It...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.