PC Review


Reply
Thread Tools Rate Thread

Create Directory / Copy Files / Delete Files

 
 
=?Utf-8?B?UGF1bCBEZW5uaXM=?=
Guest
Posts: n/a
 
      14th Feb 2006
I am looking to create a Module in Access that will create a directory based
on the current month/ year and then move all files from one direct to it.

ie create directory "C:\reporting\2006 Jan"
copy "C:\reporting\data\*.*" "C:\reporting\2006 Jan"
delete "C:\reporting\data\*.*"

Do you know the syntax please?
Also want it so it doesn't prompt for confirmation?
 
Reply With Quote
 
 
 
 
Douglas J Steele
Guest
Posts: n/a
 
      14th Feb 2006
To create a directory, use MkDir.

Assuming C:\Reporting already exists, you'd use:

MkDir "C:\Reporting\" & Format(Date(), "yyyy mmm")

To move files, you use the Name statement. Unfortunately, you can't use wild
cards with the Name statement (nor with the FileCopy statement, although you
can with the Kill statement). To have a VBA-only solution to your problem,
you could use something like:

Dim strCurrFile As String
Dim strCurrFolder As String
Dim strNewFolder As String

strCurrFolder = "C:\Reporting\Data\"
strNewFolder = "C:\Reporting\2006 Jan\"
strCurrFile = Dir(strCurrFolder & "*.*")
Do While Len(strCurrFile) > 0
Name strCurrFolder & strCurrFile As strNewFolder & strCurrFile
strCurrFile = Dir()
Loop

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


"Paul Dennis" <(E-Mail Removed)> wrote in message
news:A1162C92-3689-4ED8-B1A4-(E-Mail Removed)...
> I am looking to create a Module in Access that will create a directory

based
> on the current month/ year and then move all files from one direct to it.
>
> ie create directory "C:\reporting\2006 Jan"
> copy "C:\reporting\data\*.*" "C:\reporting\2006 Jan"
> delete "C:\reporting\data\*.*"
>
> Do you know the syntax please?
> Also want it so it doesn't prompt for confirmation?



 
Reply With Quote
 
=?Utf-8?B?UGF1bCBEZW5uaXM=?=
Guest
Posts: n/a
 
      15th Feb 2006
Thanks

However having problems with strCurrFile = Dir(strCurrFolder & "*.*"), when
watching strCurrFile it brings back nothing?


"Douglas J Steele" wrote:

> To create a directory, use MkDir.
>
> Assuming C:\Reporting already exists, you'd use:
>
> MkDir "C:\Reporting\" & Format(Date(), "yyyy mmm")
>
> To move files, you use the Name statement. Unfortunately, you can't use wild
> cards with the Name statement (nor with the FileCopy statement, although you
> can with the Kill statement). To have a VBA-only solution to your problem,
> you could use something like:
>
> Dim strCurrFile As String
> Dim strCurrFolder As String
> Dim strNewFolder As String
>
> strCurrFolder = "C:\Reporting\Data\"
> strNewFolder = "C:\Reporting\2006 Jan\"
> strCurrFile = Dir(strCurrFolder & "*.*")
> Do While Len(strCurrFile) > 0
> Name strCurrFolder & strCurrFile As strNewFolder & strCurrFile
> strCurrFile = Dir()
> Loop
>
> --
> Doug Steele, Microsoft Access MVP
> http://I.Am/DougSteele
> (no e-mails, please!)
>
>
> "Paul Dennis" <(E-Mail Removed)> wrote in message
> news:A1162C92-3689-4ED8-B1A4-(E-Mail Removed)...
> > I am looking to create a Module in Access that will create a directory

> based
> > on the current month/ year and then move all files from one direct to it.
> >
> > ie create directory "C:\reporting\2006 Jan"
> > copy "C:\reporting\data\*.*" "C:\reporting\2006 Jan"
> > delete "C:\reporting\data\*.*"
> >
> > Do you know the syntax please?
> > Also want it so it doesn't prompt for confirmation?

>
>
>

 
Reply With Quote
 
=?Utf-8?B?UGF1bCBEZW5uaXM=?=
Guest
Posts: n/a
 
      15th Feb 2006
Sorry my fault it does work, I just added a bit and missed a \ hence my code
is now:

MkDir "C:\eESM Reporting\Last Month\" & Format(DateAdd("m", -1, Date), "yyyy
mmm")

Dim strCurrFile As String
Dim strCurrFolder As String
Dim strNewFolder As String

strCurrFolder = "C:\eESM Reporting\Access Data\"
strNewFolder = "C:\eESM Reporting\Access Data\" & Format(DateAdd("m", -1,
Date), "yyyy mmm") & "\"
strCurrFile = Dir(strCurrFolder & "*.*")
Dir
Do While Len(strCurrFile) > 0
Name strCurrFolder & strCurrFile As strNewFolder & strCurrFile
strCurrFile = Dir()
Loop


This creates a sub directort for last month and moves all the files to that
directly as a back up and ready for this months extract.

many many thanks

"Paul Dennis" wrote:

> Thanks
>
> However having problems with strCurrFile = Dir(strCurrFolder & "*.*"), when
> watching strCurrFile it brings back nothing?
>
>
> "Douglas J Steele" wrote:
>
> > To create a directory, use MkDir.
> >
> > Assuming C:\Reporting already exists, you'd use:
> >
> > MkDir "C:\Reporting\" & Format(Date(), "yyyy mmm")
> >
> > To move files, you use the Name statement. Unfortunately, you can't use wild
> > cards with the Name statement (nor with the FileCopy statement, although you
> > can with the Kill statement). To have a VBA-only solution to your problem,
> > you could use something like:
> >
> > Dim strCurrFile As String
> > Dim strCurrFolder As String
> > Dim strNewFolder As String
> >
> > strCurrFolder = "C:\Reporting\Data\"
> > strNewFolder = "C:\Reporting\2006 Jan\"
> > strCurrFile = Dir(strCurrFolder & "*.*")
> > Do While Len(strCurrFile) > 0
> > Name strCurrFolder & strCurrFile As strNewFolder & strCurrFile
> > strCurrFile = Dir()
> > Loop
> >
> > --
> > Doug Steele, Microsoft Access MVP
> > http://I.Am/DougSteele
> > (no e-mails, please!)
> >
> >
> > "Paul Dennis" <(E-Mail Removed)> wrote in message
> > news:A1162C92-3689-4ED8-B1A4-(E-Mail Removed)...
> > > I am looking to create a Module in Access that will create a directory

> > based
> > > on the current month/ year and then move all files from one direct to it.
> > >
> > > ie create directory "C:\reporting\2006 Jan"
> > > copy "C:\reporting\data\*.*" "C:\reporting\2006 Jan"
> > > delete "C:\reporting\data\*.*"
> > >
> > > Do you know the syntax please?
> > > Also want it so it doesn't prompt for confirmation?

> >
> >
> >

 
Reply With Quote
 
=?Utf-8?B?WmFkb2sgQCBQb3J0IG9mIFNlYXR0bGU=?=
Guest
Posts: n/a
 
      12th Jun 2006
Douglas,
How could I include subfolders and their files in this copy/move code?


"Douglas J Steele" wrote:

> To create a directory, use MkDir.
>
> Assuming C:\Reporting already exists, you'd use:
>
> MkDir "C:\Reporting\" & Format(Date(), "yyyy mmm")
>
> To move files, you use the Name statement. Unfortunately, you can't use wild
> cards with the Name statement (nor with the FileCopy statement, although you
> can with the Kill statement). To have a VBA-only solution to your problem,
> you could use something like:
>
> Dim strCurrFile As String
> Dim strCurrFolder As String
> Dim strNewFolder As String
>
> strCurrFolder = "C:\Reporting\Data\"
> strNewFolder = "C:\Reporting\2006 Jan\"
> strCurrFile = Dir(strCurrFolder & "*.*")
> Do While Len(strCurrFile) > 0
> Name strCurrFolder & strCurrFile As strNewFolder & strCurrFile
> strCurrFile = Dir()
> Loop
>
> --
> Doug Steele, Microsoft Access MVP
> http://I.Am/DougSteele
> (no e-mails, please!)
>
>
> "Paul Dennis" <(E-Mail Removed)> wrote in message
> news:A1162C92-3689-4ED8-B1A4-(E-Mail Removed)...
> > I am looking to create a Module in Access that will create a directory

> based
> > on the current month/ year and then move all files from one direct to it.
> >
> > ie create directory "C:\reporting\2006 Jan"
> > copy "C:\reporting\data\*.*" "C:\reporting\2006 Jan"
> > delete "C:\reporting\data\*.*"
> >
> > Do you know the syntax please?
> > Also want it so it doesn't prompt for confirmation?

>
>
>

 
Reply With Quote
 
Douglas J. Steele
Guest
Posts: n/a
 
      13th Jun 2006
That's a bit more involved.

To do it using VBA, one way is to create a recursive routine that uses the
Dir function with the vbDirectory parameter to determine all of the
subdirectories and store them in an array, then pass each of the
subdirectories to the function. (The reason you need to store them all in an
array is that you cannot call the Dir function from within another Dir
function).

Other approaches would be to use FSO (File System Objects) or APIs.

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


"Zadok @ Port of Seattle" <Zadok @ Port of
(E-Mail Removed)> wrote in message
news:52D96908-84D7-4E58-9F37-(E-Mail Removed)...
> Douglas,
> How could I include subfolders and their files in this copy/move code?
>
>
> "Douglas J Steele" wrote:
>
>> To create a directory, use MkDir.
>>
>> Assuming C:\Reporting already exists, you'd use:
>>
>> MkDir "C:\Reporting\" & Format(Date(), "yyyy mmm")
>>
>> To move files, you use the Name statement. Unfortunately, you can't use
>> wild
>> cards with the Name statement (nor with the FileCopy statement, although
>> you
>> can with the Kill statement). To have a VBA-only solution to your
>> problem,
>> you could use something like:
>>
>> Dim strCurrFile As String
>> Dim strCurrFolder As String
>> Dim strNewFolder As String
>>
>> strCurrFolder = "C:\Reporting\Data\"
>> strNewFolder = "C:\Reporting\2006 Jan\"
>> strCurrFile = Dir(strCurrFolder & "*.*")
>> Do While Len(strCurrFile) > 0
>> Name strCurrFolder & strCurrFile As strNewFolder & strCurrFile
>> strCurrFile = Dir()
>> Loop
>>
>> --
>> Doug Steele, Microsoft Access MVP
>> http://I.Am/DougSteele
>> (no e-mails, please!)
>>
>>
>> "Paul Dennis" <(E-Mail Removed)> wrote in message
>> news:A1162C92-3689-4ED8-B1A4-(E-Mail Removed)...
>> > I am looking to create a Module in Access that will create a directory

>> based
>> > on the current month/ year and then move all files from one direct to
>> > it.
>> >
>> > ie create directory "C:\reporting\2006 Jan"
>> > copy "C:\reporting\data\*.*" "C:\reporting\2006 Jan"
>> > delete "C:\reporting\data\*.*"
>> >
>> > Do you know the syntax please?
>> > Also want it so it doesn't prompt for confirmation?

>>
>>
>>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Highly frustrated. Which setup directory should I use that allows me to read/write/create/delete files? Claire Microsoft C# .NET 1 23rd Jul 2008 04:10 PM
Copy Network Files to Local Directory, then rename orig files andvice versa ksfrye@gmail.com Microsoft Access VBA Modules 4 1st Feb 2008 03:49 AM
Create an Image Gallery with FILES in a web directory and names of files in SQL server news.microsoft.com Microsoft VB .NET 2 3rd Mar 2005 10:55 PM
Create an Image Gallery with FILES web directory and names of files in SQL server news.microsoft.com Microsoft ASP .NET 1 27th Feb 2005 03:44 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:44 AM.