Hello,
We have files ( named in the following format ) in one of our folders:
MV0001.XLS
MV0002.XLS
and so on
WV0001.XLS
WV0002.XLS
and so son
CV0001.XLS
CV0002.XLS
and so on
We need a script that will rename the files in the following way:
if filename starts with 'M', rename file to " XXXXX_SERVER1_YYYY_MM"
( where 'XXXXX' are the 2nd - 6th characters of the original file name e.g.V0001,
V0002 etc,
'AA' are constant texts,
'YYYY' is current year,
'MM' is previous month )
similarly, if filename starts with 'W', rename files to "XXXXX_SERVER2_YYYY_MM" , and if it starts with
'C', rename to "XXXXX_SERVER3_YYYY_MM".
Any help will be greatly appreciated.
2 1708
Kindly post what you have tried so far.
I tried something similar: take a look and see if it gives you any idea where to start... -
Private Sub RenameFiles(ByVal StartPath As String)
-
Dim myfolder As DirectoryInfo = New DirectoryInfo(StartPath)
-
Dim mySubfolders() As FileInfo = myfolder.GetFiles()
-
Dim strFiles() As FileInfo = myfolder.GetFiles()
-
-
For Each myItem As FileInfo In strFiles
-
'myItem.Delete()
-
'open File
-
Dim a As String = StartPath & "\" & myItem.ToString
-
-
'read File
-
Dim EntireLine1 As String
-
Dim oFile1 As System.IO.File
-
Dim oRead1 As System.IO.StreamReader
-
If System.IO.File.Exists(a) = True Then
-
oRead1 = oFile1.OpenText(a)
-
EntireLine1 = oRead1.ReadToEnd
-
oRead1.Close() 'test line
-
End If
-
Dim b As String = "2008" 'vbCrLf
-
'find date
-
date1 = EntireLine1.Substring(EntireLine1.IndexOf("DATE"), EntireLine1.IndexOf(b)) ', EntireLine1.IndexOf("2008"))
-
-
'function cuts of the end of the line where it finds a return character or line feed...
-
For i = 1 To Len(date1)
-
j = Mid(date1, i, 1)
-
If a = vbCr Or a = vbLf Then
-
Exit For
-
End If
-
Next
-
date1 = Mid(date1, 6, i - 7)
-
-
'rename File
-
If System.IO.File.Exists(a) = True Then
-
FileSystem.Rename(a, StartPath & "\" & RTrim(date1) & ".txt")
-
'System.IO.File.Move(a, StartPath & "\" & RTrim(date1) & ".txt")
-
'either works^^^^^^
-
End If
-
-
Next
-
-
End Sub
-
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Dino |
last post by:
dear all,
i've created an application for a customer where the customer can upload
..csv-files into a specified ftp-directory. on the server, a php-script,
triggered by a cronjob, reads all the...
|
by: Willem van Isselmuden |
last post by:
Hello, i have this upload script,
works fine, ik kan upload multiple files to my server,
but i want them to be saved under a different namen on the server.
My form has 4 file fields and i want...
|
by: Richard L Rosenheim |
last post by:
Correct me if I'm wrong...
It appears that out of the 1800+ classes in the .Net framework, there isn't
a file rename method (discounting the rename function in the vb namespace).
And that the...
|
by: Mullin Yu |
last post by:
I have a file, and want to replace some bytes by other bytes e.g.
Old: 1b 25
New: 1b 26 66 31 30 30 59 1b 26 66 58
How to implement? Thanks!
|
by: Patrick de Ridder |
last post by:
This is rather elementary but I cannot find it anywhere.
How do you rename a file from within a program in C# ? (In the directory I
mean.)
How do you delete a file from within a program in C# ?...
| |
by: Lalasa |
last post by:
Hi,
Can anybody tell me how many cpu cycles File.copy would take and
how many cpu cycles File.Move would take?
CFile::Rename in C++ takes just one cpu cycle. As there is no
File.Rename in C#,...
|
by: hardik |
last post by:
can anyone tell me how i can change the filename which is going to
uploaded
here is a code for uploading a file
<!-- #include file="clsUpload.asp" -->
Set objUpload = New clsUpload
If...
|
by: spacehopper_man |
last post by:
no "rename" operation in C# !!!
- this has been covered in this group before, but I can't find any good
answers.
what I am trying to do is refresh the content in a file with minimum...
|
by: vijayarl |
last post by:
Hi All,
Requirement :
1.read the content of the dir
2.seach for "prstat-Lvs" file
3.rename this file to *.txt (as this file doesn't have the file typeextension --raw file)
4.open this *.txt...
|
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,...
|
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...
| |
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,...
|
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: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The...
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |