Tuesday, November 25, 2014

How to find particular type of files in Windows OS


/*******************************************Step Starting*****************************************************/


Step1:


open
cmd, then execute bellow commands one by one.

comand1
C:
comand2:
dir *.bak /s >C:satish_serarch_results.txt

comand3:
D:

comand4:

dir *.bak /s >>C:satish_serarch_results.txt

comand5:

E:

comand6:
dir *.bak /s >>C:satish_serarch_results.txt







/*******************************************Step Starting*****************************************************/


Step2:


Create table testimport (header varchar(1000))





BULK

INSERT testimport

FROM 'c:\satish_search_result.txt'




select
* from testimport



/*******************************************Step Starting*****************************************************/


Step3:


select
* from testimport where header is null or header like '%File(s)%' or header like' Volume%' or header like '%Dir(s)%'

delete
from testimport where header is null or header like '%File(s)%' or header like ' Volume%' or header like '%Dir(s)%'








/*******************************************Step Starting*****************************************************/


step4:

alter

table testimport add jaff varchar(400)

alter
table testimport add id int identity(1,1)

update
testimport set jaff= header where substring(header,1,2)=' D'












/*******************************************Step Starting*****************************************************/


step5:
Execute the bellow cursor.




Declare
@header varchar(1000), @jaff varchar(400), @temp_val varchar(500),@id int

DECLARE
cur_emp CURSOR STATIC

FOR
SELECT header,jaff,id from testimport

OPEN
cur_emp

IF
@@CURSOR_ROWS > 0

BEGIN


FETCH
NEXT FROM cur_emp INTO @header,@jaff,@id

WHILE
@@Fetch_status = 0

begin

if

(@jaff is not null)

set
@temp_val=@jaff

else

update

testimport set jaff=@temp_val where header=@header and id=@id

FETCH
NEXT FROM cur_emp INTO @header,@jaff,@id

end

end

CLOSE

cur_emp

DEALLOCATE
cur_emp









/*******************************************Step Starting*****************************************************/


step6:


delete
from testimport where header like ' Directory of%'




















/*******************************************Step Starting*****************************************************/


Step7:

update

testimport set jaff=REPLACE(jaff,' Directory of ','')
























/*******************************************Step Starting*****************************************************/


step8:
Final Query.

select
header,SUBSTRING(header,1,20) as date,

cast
(replace(substring(ltrim(SUBSTRING(header,21,LEN(header))),1,CHARINDEX(' ',ltrim(SUBSTRING(header,21,LEN(header))))),',','') as float)

as
size_In_Byte,

case
when substring(reverse(jaff),1,1)<>'\' then jaff+'\'+ltrim(substring(ltrim(SUBSTRING(header,21,LEN(header))),CHARINDEX(' ',ltrim(SUBSTRING(header,21,LEN(header)))),LEN(header)))

else
jaff+ltrim(substring(ltrim(SUBSTRING(header,21,LEN(header))),CHARINDEX(' ',ltrim(SUBSTRING(header,21,LEN(header)))),LEN(header)))

end
as file_full_path

from
testimport























/*******************************************Step Starting*****************************************************/


Step9:
At last execute the bellow commnads to remove extra columns.

alter
table testimport drop column jaff

alter
table testimport drop column id

No comments:

Post a Comment