ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Renaming Non-Excel Files (https://www.excelbanter.com/excel-programming/368563-renaming-non-excel-files.html)

QTGlennM

Renaming Non-Excel Files
 
I am trying to figure out if I can rename non-excel files with excel.
I have a sheet with my file names in column A

G:\New Folder\Blank DA 1594.FPK
G:\New Folder\DA 1594 Example.pdf

and in column B I have the new names that I want to change them to.

G:\New Folder\Blank DA 1594 27 July 06.FPK
G:\New Folder\DA 1594 27 July 06.pdf

If anyone can help I would greatly appreciate it!!!!
Thanks in advance.

Glenn


Die_Another_Day

Renaming Non-Excel Files
 
Sub MoveFile()
Dim fso
Dim file As String, sfol As String, dfol As String, destFile
file = "Test.txt" ' change to match the file name
destFile = "TestMe.txt"
sfol = "C:\" ' change to match the source folder path
dfol = "C:\" ' change to match the destination folder path
Set fso = CreateObject("Scripting.FileSystemObject")
If Not fso.FileExists(sfol & file) Then
MsgBox sfol & file & " does not exist!", vbExclamation, "Source
File Missing"
ElseIf Not fso.FileExists(dfol & file) Then
fso.MoveFile (sfol & file), dfol & destFile
Else
MsgBox dfol & file & " already exists!", vbExclamation,
"Destination File Exists"
End If
End Sub

HTH

Die_Another_Day
QTGlennM wrote:
I am trying to figure out if I can rename non-excel files with excel.
I have a sheet with my file names in column A

G:\New Folder\Blank DA 1594.FPK
G:\New Folder\DA 1594 Example.pdf

and in column B I have the new names that I want to change them to.

G:\New Folder\Blank DA 1594 27 July 06.FPK
G:\New Folder\DA 1594 27 July 06.pdf

If anyone can help I would greatly appreciate it!!!!
Thanks in advance.

Glenn



Ron de Bruin

Renaming Non-Excel Files
 
You can also use the VBA Name function

Name "C:\SourceFolder\Test.xls" As "C:\DestFolder\TestNew.xls"


--
Regards Ron de Bruin
http://www.rondebruin.nl



"Die_Another_Day" wrote in message ups.com...
Sub MoveFile()
Dim fso
Dim file As String, sfol As String, dfol As String, destFile
file = "Test.txt" ' change to match the file name
destFile = "TestMe.txt"
sfol = "C:\" ' change to match the source folder path
dfol = "C:\" ' change to match the destination folder path
Set fso = CreateObject("Scripting.FileSystemObject")
If Not fso.FileExists(sfol & file) Then
MsgBox sfol & file & " does not exist!", vbExclamation, "Source
File Missing"
ElseIf Not fso.FileExists(dfol & file) Then
fso.MoveFile (sfol & file), dfol & destFile
Else
MsgBox dfol & file & " already exists!", vbExclamation,
"Destination File Exists"
End If
End Sub

HTH

Die_Another_Day
QTGlennM wrote:
I am trying to figure out if I can rename non-excel files with excel.
I have a sheet with my file names in column A

G:\New Folder\Blank DA 1594.FPK
G:\New Folder\DA 1594 Example.pdf

and in column B I have the new names that I want to change them to.

G:\New Folder\Blank DA 1594 27 July 06.FPK
G:\New Folder\DA 1594 27 July 06.pdf

If anyone can help I would greatly appreciate it!!!!
Thanks in advance.

Glenn





Hankster

Renaming Non-Excel Files
 
Many thanks for this! I have exactly the same issue, with a long list of file
names, including the path, in Column A of a spreadsheet, and the new names
and path in Column B.

Since I am a non-technical person, I do not know how to adapt this code for
my purposes.

In my case I have a folder called NameStuff with the Excel spreadsheet in it
that has the old and new names, called this NameFile. There are two sub
folders in the folder. The folder with the files with the old names (in
Column A of NameFile) is called EntriesAll; and a second, empty folder
called EntriesAllRandom. (I am renaming a list of files with random numbers
rather than a descriptive name; this is for masking entrant names for the
judges.)

How might I adapt the code for my instance?

Many, many thanks in advance!
Hank


"Die_Another_Day" wrote:

Sub MoveFile()
Dim fso
Dim file As String, sfol As String, dfol As String, destFile
file = "Test.txt" ' change to match the file name
destFile = "TestMe.txt"
sfol = "C:\" ' change to match the source folder path
dfol = "C:\" ' change to match the destination folder path
Set fso = CreateObject("Scripting.FileSystemObject")
If Not fso.FileExists(sfol & file) Then
MsgBox sfol & file & " does not exist!", vbExclamation, "Source
File Missing"
ElseIf Not fso.FileExists(dfol & file) Then
fso.MoveFile (sfol & file), dfol & destFile
Else
MsgBox dfol & file & " already exists!", vbExclamation,
"Destination File Exists"
End If
End Sub

HTH

Die_Another_Day
QTGlennM wrote:
I am trying to figure out if I can rename non-excel files with excel.
I have a sheet with my file names in column A

G:\New Folder\Blank DA 1594.FPK
G:\New Folder\DA 1594 Example.pdf

and in column B I have the new names that I want to change them to.

G:\New Folder\Blank DA 1594 27 July 06.FPK
G:\New Folder\DA 1594 27 July 06.pdf

If anyone can help I would greatly appreciate it!!!!
Thanks in advance.

Glenn




Hankster

Renaming Non-Excel Files
 
Hi - I'd received a reply from Ron, which I am posting for the record from
him:

This code will read the list of file names and paths from Column A and copy
them and save them to a destination folder with the names in Column B.

Many thanks again!!!!

Sub test2()
Dim cell As Range
For Each cell In Columns("A").SpecialCells(xlCellTypeConstants)

'we check if the file exist in Column A before we try to copy it
If Dir(cell.Value) < "" Then
FileCopy cell.Value, cell.Offset(0, 1).Value
End If

Next cell
End Sub


Best,
Hank




"Hankster" wrote:

Many thanks for this! I have exactly the same issue, with a long list of file
names, including the path, in Column A of a spreadsheet, and the new names
and path in Column B.

Since I am a non-technical person, I do not know how to adapt this code for
my purposes.

In my case I have a folder called NameStuff with the Excel spreadsheet in it
that has the old and new names, called this NameFile. There are two sub
folders in the folder. The folder with the files with the old names (in
Column A of NameFile) is called EntriesAll; and a second, empty folder
called EntriesAllRandom. (I am renaming a list of files with random numbers
rather than a descriptive name; this is for masking entrant names for the
judges.)

How might I adapt the code for my instance?

Many, many thanks in advance!
Hank


"Die_Another_Day" wrote:

Sub MoveFile()
Dim fso
Dim file As String, sfol As String, dfol As String, destFile
file = "Test.txt" ' change to match the file name
destFile = "TestMe.txt"
sfol = "C:\" ' change to match the source folder path
dfol = "C:\" ' change to match the destination folder path
Set fso = CreateObject("Scripting.FileSystemObject")
If Not fso.FileExists(sfol & file) Then
MsgBox sfol & file & " does not exist!", vbExclamation, "Source
File Missing"
ElseIf Not fso.FileExists(dfol & file) Then
fso.MoveFile (sfol & file), dfol & destFile
Else
MsgBox dfol & file & " already exists!", vbExclamation,
"Destination File Exists"
End If
End Sub

HTH

Die_Another_Day
QTGlennM wrote:
I am trying to figure out if I can rename non-excel files with excel.
I have a sheet with my file names in column A

G:\New Folder\Blank DA 1594.FPK
G:\New Folder\DA 1594 Example.pdf

and in column B I have the new names that I want to change them to.

G:\New Folder\Blank DA 1594 27 July 06.FPK
G:\New Folder\DA 1594 27 July 06.pdf

If anyone can help I would greatly appreciate it!!!!
Thanks in advance.

Glenn





All times are GMT +1. The time now is 11:29 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com