dbTalk Databases Forums  

inserting a file list into a SQL table

microsoft.public.sqlserver.dts microsoft.public.sqlserver.dts


Discuss inserting a file list into a SQL table in the microsoft.public.sqlserver.dts forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
jaylou
 
Posts: n/a

Default inserting a file list into a SQL table - 07-19-2006 , 02:26 PM






Is there a way to grab all the file names in a directory and populating a SQL
table with them? I am trying to create 2 different jobs:
1) I want to get a list of all my backup files in my directory and move all
files over one week old to an archive folder.
2) I want to grab zip files that are over 3GIG and move them off to a
different folder as well.

I need a way to grab the files by name and also by size.
Is this possible?
TIA,
Joe

Reply With Quote
  #2  
Old   
Roy Harvey
 
Posts: n/a

Default Re: inserting a file list into a SQL table - 07-19-2006 , 03:25 PM






create table #dir (line varchar(255) NULL)

INSERT #dir
exec master..xp_cmdshell 'dir "C:\WINDOWS" /-C'

select *
from #dir
where line IS NOT NULL
and line NOT LIKE '%<DIR>%'
and substring(line,1,1) <> ' '

Using SUBSTRING and CONVERT against #dir.line I leave to you.

Roy Harvey
Beacon Falls, CT

On Wed, 19 Jul 2006 12:26:01 -0700, jaylou
<jaylou (AT) discussions (DOT) microsoft.com> wrote:

Quote:
Is there a way to grab all the file names in a directory and populating a SQL
table with them? I am trying to create 2 different jobs:
1) I want to get a list of all my backup files in my directory and move all
files over one week old to an archive folder.
2) I want to grab zip files that are over 3GIG and move them off to a
different folder as well.

I need a way to grab the files by name and also by size.
Is this possible?
TIA,
Joe

Reply With Quote
  #3  
Old   
jaylou
 
Posts: n/a

Default Re: inserting a file list into a SQL table - 07-19-2006 , 03:44 PM



Thank you! That did it.

One thing use /B instead of /-C and there is no need for modification it
will only bring in file names.

Thanks again!
Joe


"Roy Harvey" wrote:

Quote:
create table #dir (line varchar(255) NULL)

INSERT #dir
exec master..xp_cmdshell 'dir "C:\WINDOWS" /-C'

select *
from #dir
where line IS NOT NULL
and line NOT LIKE '%<DIR>%'
and substring(line,1,1) <> ' '

Using SUBSTRING and CONVERT against #dir.line I leave to you.

Roy Harvey
Beacon Falls, CT

On Wed, 19 Jul 2006 12:26:01 -0700, jaylou
jaylou (AT) discussions (DOT) microsoft.com> wrote:

Is there a way to grab all the file names in a directory and populating a SQL
table with them? I am trying to create 2 different jobs:
1) I want to get a list of all my backup files in my directory and move all
files over one week old to an archive folder.
2) I want to grab zip files that are over 3GIG and move them off to a
different folder as well.

I need a way to grab the files by name and also by size.
Is this possible?
TIA,
Joe


Reply With Quote
  #4  
Old   
Roy Harvey
 
Posts: n/a

Default Re: inserting a file list into a SQL table - 07-19-2006 , 04:41 PM



On Wed, 19 Jul 2006 13:44:01 -0700, jaylou
<jaylou (AT) discussions (DOT) microsoft.com> wrote:

Quote:
Thank you! That did it.

One thing use /B instead of /-C and there is no need for modification it
will only bring in file names.
The original post indicated "I need a way to grab the files by name
and also by size" so I used a format that included the size. Certainly
of all you need is the name then /B is simpler by far.

Roy


Reply With Quote
Reply




Thread Tools
Display Modes

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.