mingfattt
asked on
file existing
i have the following code
declare @return int
declare @WorkWeek varchar(255)
declare @WorkYear varchar(255)
set @WorkWeek = DatePart(week,getdate()-1)
set @WorkYear = DatePart(year,getdate()-1)
SET @FolderName = 'WW'+@WorkWeek+''''+@WorkY ear+''
select @filename = '\\agmpimo173\Brio Schedule\'+ @FolderName +''
EXEC master..xp_fileexist @filename, @return OUT
print @return
but no matter the file is there or not the return value is '0' please help.. many thanx in advance
Me, yee
declare @return int
declare @WorkWeek varchar(255)
declare @WorkYear varchar(255)
set @WorkWeek = DatePart(week,getdate()-1)
set @WorkYear = DatePart(year,getdate()-1)
SET @FolderName = 'WW'+@WorkWeek+''''+@WorkY
select @filename = '\\agmpimo173\Brio Schedule\'+ @FolderName +''
EXEC master..xp_fileexist @filename, @return OUT
print @return
but no matter the file is there or not the return value is '0' please help.. many thanx in advance
Me, yee
You can do this with the filesystem object:
DECLARE @FS int
DECLARE @OLEResult int
DECLARE @Exists int
EXECUTE @OLEResult = sp_OACreate 'Scripting.FileSystemObjec t', @FS OUT
IF @OLEResult <> 0
BEGIN
PRINT 'Error while instancing Scripting.FileSystemObject '
END
EXECUTE @OLEResult = sp_OAMethod @FS, 'FolderExists', @Exists OUT, '\\agmpimo173\Brio Schedule\'+ @FolderName +''
EXECUTE @OLEResult = sp_OADestroy @FS
-Paul.
DECLARE @FS int
DECLARE @OLEResult int
DECLARE @Exists int
EXECUTE @OLEResult = sp_OACreate 'Scripting.FileSystemObjec
IF @OLEResult <> 0
BEGIN
PRINT 'Error while instancing Scripting.FileSystemObject
END
EXECUTE @OLEResult = sp_OAMethod @FS, 'FolderExists', @Exists OUT, '\\agmpimo173\Brio Schedule\'+ @FolderName +''
EXECUTE @OLEResult = sp_OADestroy @FS
-Paul.
ASKER
EXECUTE @OLEResult = sp_OAMethod @FS, 'FolderExists', @Exists OUT, '\\agmpimo173\Brio Schedule\'+@FolderName
this part doest really can run because something wrong with the + Please advise
this part doest really can run because something wrong with the + Please advise
try this
You can't access the network files using master..xp_fileexist . Create a map network drive for \agmpimo173.
let say
\agmpimo173 is mapped to G drive... then access the file with below format
SET @FolderName = 'WW'+@WorkWeek+''''+@WorkY ear+''
select @filename = 'G:\Brio Schedule\'+ @FolderName +''
EXEC master..xp_fileexist @filename, @return OUT
print @return
itsvtk
You can't access the network files using master..xp_fileexist . Create a map network drive for \agmpimo173.
let say
\agmpimo173 is mapped to G drive... then access the file with below format
SET @FolderName = 'WW'+@WorkWeek+''''+@WorkY
select @filename = 'G:\Brio Schedule\'+ @FolderName +''
EXEC master..xp_fileexist @filename, @return OUT
print @return
itsvtk
plz ignore my previous comments.... those are not working
have a lookt into this
https://www.experts-exchange.com/questions/21131991/Deleting-files-through-tsql.html
have a lookt into this
https://www.experts-exchange.com/questions/21131991/Deleting-files-through-tsql.html
ASKER
well the problem now is i want to detect the folder but not the file.... i m sorry for my first question
try this
EXECUTE @OLEResult = sp_OAMethod @FS, 'FileExists', @Exists OUT, '\\agmpimo173\Brio Schedule\'+@FolderName
EXECUTE @OLEResult = sp_OAMethod @FS, 'FileExists', @Exists OUT, '\\agmpimo173\Brio Schedule\'+@FolderName
ASKER
the error message...
Incorrect syntax near '+'.
btw can you show me the code!!! i m really confusing... thanx
Incorrect syntax near '+'.
btw can you show me the code!!! i m really confusing... thanx
can you paste the latest code here... so i will check it
Yeah, Please paste all the code including where you declare and set @FolderName. Otherwise, the code should be working - I tested it before I posted it.
ASKER
here here is my code
declare @FolderName varchar(255)
declare @filename varchar(255)
declare @return int
declare @WorkWeek varchar(255)
declare @WorkYear varchar(255)
DECLARE @FS int
DECLARE @OLEResult int
DECLARE @Exists int
set @WorkWeek = DatePart(week,getdate()-1)
set @WorkYear = DatePart(year,getdate()-1)
SET @FolderName = 'WW'+ @WorkWeek +''''+ @WorkYear +''
print @FolderName
EXECUTE @OLEResult = sp_OACreate 'Scripting.FileSystemObjec t', @FS OUT
IF @OLEResult <> 0
BEGIN
PRINT 'Error while instancing Scripting.FileSystemObject '
END
EXECUTE @OLEResult = sp_OAMethod @FS, 'FolderExists', @Exists OUT, '\\agmpimo173\Brio Schedule\'+ @FolderName +''
EXECUTE @OLEResult = sp_OADestroy @FS
declare @FolderName varchar(255)
declare @filename varchar(255)
declare @return int
declare @WorkWeek varchar(255)
declare @WorkYear varchar(255)
DECLARE @FS int
DECLARE @OLEResult int
DECLARE @Exists int
set @WorkWeek = DatePart(week,getdate()-1)
set @WorkYear = DatePart(year,getdate()-1)
SET @FolderName = 'WW'+ @WorkWeek +''''+ @WorkYear +''
print @FolderName
EXECUTE @OLEResult = sp_OACreate 'Scripting.FileSystemObjec
IF @OLEResult <> 0
BEGIN
PRINT 'Error while instancing Scripting.FileSystemObject
END
EXECUTE @OLEResult = sp_OAMethod @FS, 'FolderExists', @Exists OUT, '\\agmpimo173\Brio Schedule\'+ @FolderName +''
EXECUTE @OLEResult = sp_OADestroy @FS
sp_OAMethod doesnt like the concatenation taking place within the parameter. Set the full path to @FolderName or use an intermediate variable, like this:
DECLARE @Fldr varchar(255)
SET @Fldr='\\agmpimo173\Brio Schedule\'+ @FolderName +''
EXECUTE @OLEResult = sp_OAMethod @FS, 'FolderExists', @Exists OUT, @Fldr
-Paul.
DECLARE @Fldr varchar(255)
SET @Fldr='\\agmpimo173\Brio Schedule\'+ @FolderName +''
EXECUTE @OLEResult = sp_OAMethod @FS, 'FolderExists', @Exists OUT, @Fldr
-Paul.
ASKER
welll its work.. but the thing is i get @OLEResult as 0 which in regards to my folder existing... anyone please tell..
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
me, yee