Renaming file

Hello all,

Hope this is the right group and someone can help me further. I have a 
mainly VBA question but it is (should be...) a part of my access DB utility.

I would like to create a Sub to rename a file in a windows directory. I know 
that in a directory there in a file which has a part '_SB' on in the name, I 
would like to rename this file to lets say Test_SB.PDF. Before the rename 
action, I will check if the file expected it there (FileExists). I cant 
figure out using fso how to get the full name of the file containing the 
'_SB' (maybe like FirstTest_SB.ASC) and then rename it to Test_SB.PDF or so. 
Ideally the sub should be something like RenameFile( Path, 
KnownFileNameConstant, NewFileName) because I will have to loop thru many 
directories to rename files from which the locations are stored in my DB 
tables and the file name constant will be several different once.

Any help or direction to a web side would be great. I have looked but can't 
find the right method and the Microsoft Access / VBA sites.

Thx,
Ludovic 


0
Vsn
7/30/2007 5:47:32 PM
access.formscoding 7493 articles. 0 followers. Follow

4 Replies
621 Views

Similar Articles

[PageSpeed] 35

What happens if you have more than one file with _SB in it?

There's no need to invoke the overhead of FSO, by the way.

Dim strFolder As String
Dim strFile As String

  strFolder ="C:\Windows\"
  strFile = Dir(strFolder & "*_SB*")
  If Len(strFile) > 0 Then
    Name strFolder & strFile As strFolder & strFile & ".xxx"
  End If


-- 
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)


"Vsn" <vsn at hotmail> wrote in message 
news:%23INz4Gt0HHA.3788@TK2MSFTNGP02.phx.gbl...
> Hello all,
>
> Hope this is the right group and someone can help me further. I have a 
> mainly VBA question but it is (should be...) a part of my access DB 
> utility.
>
> I would like to create a Sub to rename a file in a windows directory. I 
> know that in a directory there in a file which has a part '_SB' on in the 
> name, I would like to rename this file to lets say Test_SB.PDF. Before the 
> rename action, I will check if the file expected it there (FileExists). I 
> cant figure out using fso how to get the full name of the file containing 
> the '_SB' (maybe like FirstTest_SB.ASC) and then rename it to Test_SB.PDF 
> or so. Ideally the sub should be something like RenameFile( Path, 
> KnownFileNameConstant, NewFileName) because I will have to loop thru many 
> directories to rename files from which the locations are stored in my DB 
> tables and the file name constant will be several different once.
>
> Any help or direction to a web side would be great. I have looked but 
> can't find the right method and the Microsoft Access / VBA sites.
>
> Thx,
> Ludovic
> 


0
Douglas
7/30/2007 6:00:02 PM
mmmm...... Surly if the are 2 or more files with '_SB' in the directory, 
people using the DB did not follow the protocol, which of course they never 
do.

Now you did make me think again, is there a way to check if there are 
multiple files in the folder, with the '_SB' constant in the file name? Can 
i retrieve those file names and then choose which file to rename?

Thx,
Ludovic


"Douglas J. Steele" <NOSPAM_djsteele@NOSPAM_canada.com> wrote in message 
news:un7x0Nt0HHA.4236@TK2MSFTNGP06.phx.gbl...
> What happens if you have more than one file with _SB in it?
>
> There's no need to invoke the overhead of FSO, by the way.
>
> Dim strFolder As String
> Dim strFile As String
>
>  strFolder ="C:\Windows\"
>  strFile = Dir(strFolder & "*_SB*")
>  If Len(strFile) > 0 Then
>    Name strFolder & strFile As strFolder & strFile & ".xxx"
>  End If
>
>
> -- 
> Doug Steele, Microsoft Access MVP
> http://I.Am/DougSteele
> (no e-mails, please!)
>
>
> "Vsn" <vsn at hotmail> wrote in message 
> news:%23INz4Gt0HHA.3788@TK2MSFTNGP02.phx.gbl...
>> Hello all,
>>
>> Hope this is the right group and someone can help me further. I have a 
>> mainly VBA question but it is (should be...) a part of my access DB 
>> utility.
>>
>> I would like to create a Sub to rename a file in a windows directory. I 
>> know that in a directory there in a file which has a part '_SB' on in the 
>> name, I would like to rename this file to lets say Test_SB.PDF. Before 
>> the rename action, I will check if the file expected it there 
>> (FileExists). I cant figure out using fso how to get the full name of the 
>> file containing the '_SB' (maybe like FirstTest_SB.ASC) and then rename 
>> it to Test_SB.PDF or so. Ideally the sub should be something like 
>> RenameFile( Path, KnownFileNameConstant, NewFileName) because I will have 
>> to loop thru many directories to rename files from which the locations 
>> are stored in my DB tables and the file name constant will be several 
>> different once.
>>
>> Any help or direction to a web side would be great. I have looked but 
>> can't find the right method and the Microsoft Access / VBA sites.
>>
>> Thx,
>> Ludovic
>>
>
> 


0
Vsn
7/31/2007 3:06:33 AM
Dim lngFileCount As Long
Dim strFolder As String
Dim strFile As String
Dim strFiles() As String

  strFolder ="C:\Windows\"
  strFile = Dir(strFolder & "*_SB*")
  While Len(strFile) > 0 Then
    ReDim Preserve strFiles(lngFileCount)
    strFiles(lngFileCount) = strFolder & strFile
    lngFileCount = lngFileCount + 1
    strFile = Dir()
  Loop

  Select Case lngFileCount
    Case 0
      MsgBox "No _SB file found in " & strFolder
    Case 1
      Name strFolder & strFile As strFolder & strFile & ".xxx"
    Case Else
      MsgBox lngFileCount & " _SB files found in " & strFolder
' At this point, the array strFiles will contain the list of all of the 
files found.
   End Select

-- 
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)


"Vsn" <vsn at hotmail> wrote in message 
news:evF9c$x0HHA.4004@TK2MSFTNGP05.phx.gbl...
> mmmm...... Surly if the are 2 or more files with '_SB' in the directory, 
> people using the DB did not follow the protocol, which of course they 
> never do.
>
> Now you did make me think again, is there a way to check if there are 
> multiple files in the folder, with the '_SB' constant in the file name? 
> Can i retrieve those file names and then choose which file to rename?
>
> Thx,
> Ludovic
>
>
> "Douglas J. Steele" <NOSPAM_djsteele@NOSPAM_canada.com> wrote in message 
> news:un7x0Nt0HHA.4236@TK2MSFTNGP06.phx.gbl...
>> What happens if you have more than one file with _SB in it?
>>
>> There's no need to invoke the overhead of FSO, by the way.
>>
>> Dim strFolder As String
>> Dim strFile As String
>>
>>  strFolder ="C:\Windows\"
>>  strFile = Dir(strFolder & "*_SB*")
>>  If Len(strFile) > 0 Then
>>    Name strFolder & strFile As strFolder & strFile & ".xxx"
>>  End If
>>
>>
>> -- 
>> Doug Steele, Microsoft Access MVP
>> http://I.Am/DougSteele
>> (no e-mails, please!)
>>
>>
>> "Vsn" <vsn at hotmail> wrote in message 
>> news:%23INz4Gt0HHA.3788@TK2MSFTNGP02.phx.gbl...
>>> Hello all,
>>>
>>> Hope this is the right group and someone can help me further. I have a 
>>> mainly VBA question but it is (should be...) a part of my access DB 
>>> utility.
>>>
>>> I would like to create a Sub to rename a file in a windows directory. I 
>>> know that in a directory there in a file which has a part '_SB' on in 
>>> the name, I would like to rename this file to lets say Test_SB.PDF. 
>>> Before the rename action, I will check if the file expected it there 
>>> (FileExists). I cant figure out using fso how to get the full name of 
>>> the file containing the '_SB' (maybe like FirstTest_SB.ASC) and then 
>>> rename it to Test_SB.PDF or so. Ideally the sub should be something like 
>>> RenameFile( Path, KnownFileNameConstant, NewFileName) because I will 
>>> have to loop thru many directories to rename files from which the 
>>> locations are stored in my DB tables and the file name constant will be 
>>> several different once.
>>>
>>> Any help or direction to a web side would be great. I have looked but 
>>> can't find the right method and the Microsoft Access / VBA sites.
>>>
>>> Thx,
>>> Ludovic
>>>
>>
>>
>
> 


0
Douglas
7/31/2007 12:22:34 PM
Very impresive. Thanks a lot for the help.

Ludovic

"Douglas J. Steele" <NOSPAM_djsteele@NOSPAM_canada.com> wrote in message 
news:uZE66120HHA.5736@TK2MSFTNGP04.phx.gbl...
>
> Dim lngFileCount As Long
> Dim strFolder As String
> Dim strFile As String
> Dim strFiles() As String
>
>  strFolder ="C:\Windows\"
>  strFile = Dir(strFolder & "*_SB*")
>  While Len(strFile) > 0 Then
>    ReDim Preserve strFiles(lngFileCount)
>    strFiles(lngFileCount) = strFolder & strFile
>    lngFileCount = lngFileCount + 1
>    strFile = Dir()
>  Loop
>
>  Select Case lngFileCount
>    Case 0
>      MsgBox "No _SB file found in " & strFolder
>    Case 1
>      Name strFolder & strFile As strFolder & strFile & ".xxx"
>    Case Else
>      MsgBox lngFileCount & " _SB files found in " & strFolder
> ' At this point, the array strFiles will contain the list of all of the 
> files found.
>   End Select
>
> -- 
> Doug Steele, Microsoft Access MVP
> http://I.Am/DougSteele
> (no e-mails, please!)
>
>
> "Vsn" <vsn at hotmail> wrote in message 
> news:evF9c$x0HHA.4004@TK2MSFTNGP05.phx.gbl...
>> mmmm...... Surly if the are 2 or more files with '_SB' in the directory, 
>> people using the DB did not follow the protocol, which of course they 
>> never do.
>>
>> Now you did make me think again, is there a way to check if there are 
>> multiple files in the folder, with the '_SB' constant in the file name? 
>> Can i retrieve those file names and then choose which file to rename?
>>
>> Thx,
>> Ludovic
>>
>>
>> "Douglas J. Steele" <NOSPAM_djsteele@NOSPAM_canada.com> wrote in message 
>> news:un7x0Nt0HHA.4236@TK2MSFTNGP06.phx.gbl...
>>> What happens if you have more than one file with _SB in it?
>>>
>>> There's no need to invoke the overhead of FSO, by the way.
>>>
>>> Dim strFolder As String
>>> Dim strFile As String
>>>
>>>  strFolder ="C:\Windows\"
>>>  strFile = Dir(strFolder & "*_SB*")
>>>  If Len(strFile) > 0 Then
>>>    Name strFolder & strFile As strFolder & strFile & ".xxx"
>>>  End If
>>>
>>>
>>> -- 
>>> Doug Steele, Microsoft Access MVP
>>> http://I.Am/DougSteele
>>> (no e-mails, please!)
>>>
>>>
>>> "Vsn" <vsn at hotmail> wrote in message 
>>> news:%23INz4Gt0HHA.3788@TK2MSFTNGP02.phx.gbl...
>>>> Hello all,
>>>>
>>>> Hope this is the right group and someone can help me further. I have a 
>>>> mainly VBA question but it is (should be...) a part of my access DB 
>>>> utility.
>>>>
>>>> I would like to create a Sub to rename a file in a windows directory. I 
>>>> know that in a directory there in a file which has a part '_SB' on in 
>>>> the name, I would like to rename this file to lets say Test_SB.PDF. 
>>>> Before the rename action, I will check if the file expected it there 
>>>> (FileExists). I cant figure out using fso how to get the full name of 
>>>> the file containing the '_SB' (maybe like FirstTest_SB.ASC) and then 
>>>> rename it to Test_SB.PDF or so. Ideally the sub should be something 
>>>> like RenameFile( Path, KnownFileNameConstant, NewFileName) because I 
>>>> will have to loop thru many directories to rename files from which the 
>>>> locations are stored in my DB tables and the file name constant will be 
>>>> several different once.
>>>>
>>>> Any help or direction to a web side would be great. I have looked but 
>>>> can't find the right method and the Microsoft Access / VBA sites.
>>>>
>>>> Thx,
>>>> Ludovic
>>>>
>>>
>>>
>>
>>
>
> 


0
Vsn
8/1/2007 3:23:05 AM
Reply:

Similar Artilces:

Cannot read Attached files
I am not able to read attached files. At link the file name is displaying but it is disable one, cannot open one. Please help to retrieve the attachments comes through my mail. Thank you. Khan in outlook or ms outlook there is an option for not openning attachments, i believe under tools ===accounts-- then look for a section where is says disable or enable attachments, if not email me at ianfuentes@hotmail.com will give you exact procedure >-----Original Message----- >I am not able to read attached files. >At link the file name is displaying but it is disable >one, cann...

normal.dot file and macros
I have used Microsoft WORD 2000 for many years and had no problem with Macros. Now I installed WORD 2003 on a different computer and cannot find the normal.dot file even with changing folder's settings to view hidden files. There is nothing visible in templates under Microsoft unless I create one, and normal.dot does not come up with an file explorer search. I can create macros in normal.dot in the WORD process I normally used in Word 2000, and they apply to all open files. However, when I closed word and re-open, I have no working Macros. Therefore, I need help on ...

Adding Date to File Name on Save
Is there a way to save a workbook under a "new" name by automatically adding the date when saving on exit? Idea is to ensure previous version is kept as a back-up and allow other users of same file to access the most up-to-date version. Many thanks for any help. David I don't believe you can force a workbook to be saved under another name unless it is "read-only". As a developer you might add a button or keyboard shortcut that runs a macro to do the save. The macro could always make the current date part of the file's name. Something like: ThisWorkbo...

Some question about different files
Hello! When I create a default SDI MFC application some files are generated. There are two file that I have questions about. These are Mainframe.h/cpp and TestView.h/cpp In my case the project has name test so the file was called TestView.h/cpp. The actual main frame window that the application creates is the mainframe file and has the following definition. Class CMainFrame is derived from CFrameWnd like class CMainFrame : public CFrameWnd. As I think a view as in filename testview should also be a window but I don't have two windows. The class CTestView is deriverd from CView like ...

How do I branch to another sheet in the same file?
I have a file with multiple sheets. Depending on who uses the file, I want them to be able to click on a button (or other object) and have it display one of the other sheets. It seems like this should be simple but can't quite figure it out. I really don't want ot get involved with writing macros. Thank you for any help! 1. Please make use of a Hyperlink. Regards. Here's an example. Assume your sheets are all numbered consecutively, i.e. Sheet1, Sheet2, Sheet3, Sheet4 etc, then in Sheet1 cell A1 you enter a number. In B2 enter this formula: =HYPERLINK("#Sheet"&a...

File Size
What is the easiest way to find out the size of a file. Thanks, Ken GetFileSize[Ex]() API's or GetFileAttributesEx() API. -- Cheers Check Abdoul [VC++ MVP] ----------------------------------- "Ken->" <handsom@comcast.netspicedham> wrote in message news:ArqdnddlcZoeuqfdRVn-uw@comcast.com... > What is the easiest way to find out the size of a file. > Thanks, > Ken > > Tell us what are the functions you have in mind "Ken->" <handsom@comcast.netspicedham> a �crit dans le message de news: ArqdnddlcZoeuqfdRVn-uw@comcast.com.....

Rename Server
I was would like to know if it is possible to rename a server on which Exchange 2000 has been install onto, would this have an effect on exchange wayne The Exchange services won't start after a server rename. Build a new server with the new name and move the mailboxes to it. -- Neil Hobson Exchange MVP http://www.msexchange.org/Neil_Hobson/ "WB" <wmb2003@zoom.co.uk> wrote in message news:u5TGyDCpGHA.2360@TK2MSFTNGP05.phx.gbl... >I was would like to know if it is possible to rename a server on which >Exchange 2000 has been install onto, would this have ...

how to rename a file #2
What MFC class/function would I use to rename a file. Assume the file is not being accessed by any application. I have typically used the C run time library function 'rename' but his there a comparable MFC or SDK function? Thanks Ian Hi, You could use CFile::Rename. Regards Andy Mortimer [MS] Please do not send email directly to this alias. This alias is for newsgroup purposes only This posting is provided "AS IS" with no warranties, and confers no rights. OR if you wish to include a script sample in your post please add "Use of included script samples a...

What files do I want to back up from Outlook 2007 ?
What files do I want to back up from Outlook 2007 ? I had Office 2007 running my registry had an issue and I now have to reinstall my programs. I can not get my code to reload Office 2007 because my code was stored in an email from Microsoft which I can not open. Any ideas ? Thanks Take a look here, it may help: http://www.slipstick.com/config/backup.htm --=81 Milly Staples [MVP - Outlook] Post all replies to the group to keep the discussion intact. All unsolicited mail sent to my personal account will be deleted without reading. =20 After furious head scratching, q1m7ot001@sneakema...

Sharing .pst file
Hello, Is it possible to share the .pst file of Outlook. So it is possible for 2 people changing the agenda at the same time in the same .pst file? Thanks in advance No. Outlook.pst files require exclusive read/write access at all times so it cannot be shared. --� Milly Staples [MVP - Outlook] Post all replies to the group to keep the discussion intact. Due to the (insert latest virus name here) virus, all mail sent to my personal account will be deleted without reading. After searching google.groups.com and finding no answer, Waterman asked: | Hello, | | | Is it possib...

how do i rename a sheet if the rename tab is inactive?
I tried to rename a sheet in a workbook but discovered that the rename option is inactive when i right-clicked on the sheet. How do i make it active ? Hi, This would happen if the 'workbook' was protected. Tools|Protection|Unprotect workbook -- Mike When competing hypotheses are otherwise equal, adopt the hypothesis that introduces the fewest assumptions while still sufficiently answering the question. "Nelson" wrote: > I tried to rename a sheet in a workbook but discovered that the rename option > is inactive when i right-clicked on the ...

Outlook Express 6 XPSP2 locks up while drag & dropping files.
Hi, To get I to someone that may bea ble to do something about it. (ie: bug report), I am posting this. The normal bug report process does not come up. It is very repeatable, while trying to drag and drop filess to a different folder, the program will lock up on certain emails that have content that requires one to accepting or reject do to security settings. If you are not already viewing the email trying to drag and drop it can cause this to happen. (In my case, it is an eBay generated email that I have previously viewed and am trying to sort to folders so I can find it e...

open an .exe file for its resources
Hi, In one of Mike Blaszczak's books for VC++ 6.0, he said we can File/Open an executable file (.exe or .dll) and then edit the resources (e.g. a dialog) in the executable's immage. I tried but nothing happened. The only thing I saw was a blank work space with the executable's file name on the file view. Do you know how to make it happen? Thanks. Tony ps. No copy-right violation activity will be involved. I don't know if this worked in 6.0 (haven't used for some time), but I just tried opening an EXE in 2003 and it works fine. It displays the resources in a ...

Slow to Open File
I have a file with about 40,000 records. All 40,000 records have hyperlinks in Column A. This file takes about one minute to open, and is very slow to edit, sort and modify! When I remove Column A, the file opens quickly. Is there a better way to store or reference my hyperlinks so that my file will open/process more quickly? Replace each hyperlink with the Hyperlink function... =HYPERLINK(location, name to display) The function uses less memory. -- Jim Cone Portland, Oregon USA "iamnu" <iamnubw@gmail.com> wrote in message I have a file with about 40,000 records. All 40...

Renaming your password
I wanted to ask if someone could tell me if it is possible to rename your password? I would like to keep my existing e-mail accounts, and all of my folders and saved information. However, I was told that if someone knows my password and e-mail address, they can access my account from any other computer, anywhere. So, is there some way to handle this without losing the small group of links and e-mail boxes, etc. without bailing out? To change your email account password, contact the account provider, or check their website for assistance. -- Dave N. MS-MVP (Mail) ...

Lotus 1-2-3 file
Is there any way to open a Lotus .wk4 file in Excel 2000 without everything changing? ...

Opening Text Files and Re-Saving Them
Hi. I am trying to write some code which will allow a user to select a folder and then will open all of the text files in that folder and re-save them as excel files. I have sorted out the code to enable the user to select the folder they wish to use, but am looking some assistance on the looping to enable each of the text files to be opened and re-saved. Can anyone suggest how I might do this. Thanks. If the text files are all the same, you could record a macro that Opens, saves as an excel file, and closes the file. Then that recorded macro could be modified to open...

convert PDF file to excel 2007 file
Anyone know how to convert a PDF file to an Excel 2007 file? Need help. Thanks You use software like this. http://www.pdftransformer.com/ Bob Heideloff wrote: > Anyone know how to convert a PDF file to an Excel 2007 file? Need help. > Thanks > > ...

File Path
Need some help. I developed a macro that was used by myself, however the macro now needs to be shared. The macro opens files that are located in my C:\document and settings\max28052. These files are saved automatically once exported from the corporate database. The file is automatically named - they always have the same name regardless of the officer. Is there a way that I can change the macro to open the required files without stating the full path (as it changes) eg. instead of c:\document and settings\max28052\help.xls that it opens the logged on users eg. c:\documen...

Compare two file/colunms, hide row not does not equal list.
Excel 2000 -have two files. File "A" has 1 through 4155 records (rows with three columns) in numerical order. File "B", has a list of almost 200 rows/numbers (one column) from file "A". How can I hide the rows in file "A", not are listed in file "B"? Thanks, Jerry Not sure whether you are still monitoring this post, Jerry. Anyway, here's some thoughts ventured .. Conceptually, you should be able to achieve this via setting up a helper col and then autofiltering on the helper. Let's start by simplifying the scenario by having bo...

Automating charts from a csv file
Hello, ons of our softwares creates some csv file everyday. Is there a way to create charts automatically via excel from this csv file? Thank you Erman Ulusoy Erman - Sure, this is actually fairly easy to do. Start by recording a macro: Sub Macro2() ' ' Macro2 Macro ' Macro recorded 2/27/2004 by Jon Peltier ' ' Workbooks.Open FileName:= _ "\\holy\cow\where\is\that\file\Y03\M04\03040109CW.csv" Charts.Add ActiveChart.ChartType = xlXYScatterLinesNoMarkers ActiveChart.SetSourceData _ Source:=Sheets("03040109CW").Rang...

Ignore the 'file in use message' when opening Excel
Hi all, I am scheduling an Excel workbook using the Scheduler Tool of Windows. It just calls an Excel workbook, which opens, does some autorun processing and closes again. This works well, except when I have excel already open. In that case another instance of Excel is opened (by the scheduler) and I get the "File in Use" popup stateing that my PERSONAL.XLS is locked for editing. And gives me a chance to cancel (button). A logical thing but unhandy in this context. Is there a way to ignore this message or to add an extra parameter to the call of the worksheet to preven...

lost pst files in 2003...
I upgraded a user from Outlook 2000, to 2003. When I first opened up Outlook 2003 to setup his acct, it wanted to associate the personal folders the user had, but it couldn't locate them. I wasn't sure, and figured I'll add them after the initial setup, so I canceled out of adding them, and continued. The unfortunate part, is now I can't find his .pst files. I've searched his hard drive and network drives for "*.pst" and am unable to locate the files. I used PCI File Recovery to see if maybe they had been deleted or lost, but am still unable to locate the fi...

a class of ini file . you are very easy to write or read from an ini file.
Hi, I have wrotten a class of ini file operating. As following, Pls give me advise. You can add this class to your project to read or to write . +++++++++++++The head file.++++++++++++++++++ // IniFilesDef.h: interface for the CIniFile class. // ////////////////////////////////////////////////////////////////////// #if !defined(AFX_INIFILES_IMP_H__810C0A02_A7DF_4D48_A32E_033ADAF59235__INCLUDED_ ) #define AFX_INIFILES_IMP_H__810C0A02_A7DF_4D48_A32E_033ADAF59235__INCLUDED_ #if _MSC_VER > 1000 #pragma once #endif // _MSC_VER > 1000 typedef int INT ; typedef struct { } INIITEMS;...

Money 2002
Greetings, My bank often sends me transactions in the download that have the payee's address, not their name. Is there a way to have it automatically rename say "123 E. Main St" to "AM/PM GAS STATION", instead of me doing it each and everytime I download transactions? In microsoft.public.money, <kharless@qwest.net> wrote: >Greetings, > >My bank often sends me transactions in the download that >have the payee's address, not their name. Is there a way >to have it automatically rename say "123 E. Main St" >to "AM/PM GA...