I have a folder that is static with a daily txt file that goes into the folder. The file name is the date. If the file name has the same name every day, everything works. Is there a way I can have my script pull any txt file in the folder? (Note, file comes in, get's processed and then I have an automatic transfer that moves the file after it has been inserted to a processed folder). So there will only be one file at a time in the folder. I hope that makes sense.
Here is the script for the bulk insert:
Bulk Insert Mydata.dbo.cust_adj
From 'C:\MyData\FlatFiles\UnprocessedAdjReport\importformat.txt'
With
(
FieldTerminator= '|',
Rowterminator= '\n'
)
Go
(I've got this saved as a stored procedure btw)
So "importformat" is just the name I used while setting up my scripts, going forward it will be in bb-yyyy-mmdd-hhmmnnnn.txt, as soon as the file is inserted, I move the file from the unprocessed folder to the processed folder. There will only be the one file each day.
If anyone has any advice or assistance with this, I would greatly appreciate it.
See the link it may be what you are looking for:
http://www.kodyaz.com/articles/how-to-extract-filename-from-path-using-sql-functions.aspx
Or
http://sqljourney.wordpress.com/2010/06/08/get-list-of-files-from-a-windows-directory-to-sql-server/
Or maybe
http://www.codeproject.com/Articles/38850/An-Easy-Way-to-Get-a-File-Name-or-a-File-Extension
HTH
Related
Well, I am facing one weird issue with Copy Files task i SSIS.
I have folder A in which I have sub folders and I am using Copy files task to copy all the Excel files in sub-folders to the folder A. I noticed that with some of the excel files where I have custom date column which is restricted by list to select dates from as I don't want user to input wrong date/format.
When I run the package the excel file is copied but that date column is not getting populated.
I am not getting the reason why its happening.
Can some one help? What approach I should follow to resolve it?
So, what I did is in place of Copy file from the drop down of the component I selected move file and ran it once. And then again I ran with Copy command and it some how worked. I am not happy this though. I have put in a solution at the end of SSIS package where after the files are loaded to SQL table I am deleting them from the source folder using looping component.
For now it seem to be working. but exact reason for not copying the particular custom date field is still a question.
How can I save two files with the same file name in the same folder without renaming anyone using php?
For instance: A user has an audio file name "first.mp3"; and another user uploads another file named: "first.mp3"; and I want to save these two files without renaming any so that when people are downloading the audio from the front end, the name does not change.
I can do this by concatenating a random number to differentiate the files but I want to beat this method of renaming.
Should I be saving each file inside a unique folder and save the file names to database? but this method will create too many folders which i don't think it is appropriate.
You cannot have two files with the same name in the same folder.
You would either have to add a random string to the end of each file like you suggest or save each user's files in a directory allocated to their account.
Regards,
Leslie
Saving multiple files with the same name within the same folder is just not possible.
I'd opt for a strategy that would involve saving the original filename somewhere (in a database, for example) along with the name/path of the actual file. When the User downloads the file (presumably through a web app of some sorts), you can set the name of the file via headers with your language of choice.
You could even rename the files to something completely random when they're uploaded so you can have them all in one folder - as long as you store the original filename somewhere, you can always set it before you serve it back to the end user.
I have a process that I want to create in SSIS. What I have so far is below.
So the scenario is that a number of different file types are downloaded to a specific location - which has been created as a variable "RootFolder"
Within that RootFolder, is a folder called "Archive"
The first part of the process is to create a folder within the variable of ArchiveFolder, which is basically todays date.
Then in a For Loop Container, it copies all the files in the RootFolder to the Archive Folder. So we have a history of the files received.
The next step that I want to carry out in SSIS is to add a header line at the top of each of those text files. So all the files that still exist in the Root Folder get a header added to the top of the file. Is there something direct in SSIS to do this, or would I need a .bat file to do it and have an Execute Process Task, to call that bat file. Either way I have no idea how to achieve this bit. Your help will be appreciated.
I am facing a problem while deleting a file on a network location using SSIS, since its a zip file, contains monthly SQL Database backup file, so I need to delete the last month file before copying current month file.
May be there is some app which were using this file, I am not sure, but I wanna get rid of this file, so that I can copy new file.
Thanks
Use a file task and you should be able to delete pretty much anything on any location as long as you have the rights to do so.
I have a CGI program I have written using Perl. One of its functions is to upload pics to the server.
All of it is working well, including adding all kinds of info to a MySQL db. My question is: How can I get the uploaded pic files location and names added to the db?
I would rather that instead of changing the script to actually upload the pics to the db. I have heard horror stories of uploading binary files to databases.
Since I am new to all of this, I am at a loss. Have tried doing some research and web searches for 3 weeks now with no luck. Any suggestions or answers would be greatly appreciated. I would really hate to have to manually add all the locations/names to the db.
I am using: a Perl CGI script, MySQL db, Linux server and the files are being uploaded to the server. I AM NOT looking to add the actual files to the db. Just their location(s).
It sounds like you have your method complete where you take the upload, make it a string and toss it unto mysql similar to reading file in as a string. However since your given a filehandle versus a filename to read by CGI. You are wondering where that file actually is.
If your using CGI.pm, the upload, uploadInfo, the param for the upload, and upload private files will help you deal with the upload file sources. Where they are stashed after the remote client and the CGI are done isn't permanent usually and a minimum is volatile.
You've got a bunch of uploaded files that need to be added to the db? Should be trivial to dash off a one-off script to loop through all the files and insert the details into the DB. If they're all in one spot, then a simple opendir()/readdir() type loop would catch them all, otherwise you can make a list of file paths to loop over and loop over that.
If you've talking about recording new uploads in the server, then it would be something along these lines:
user uploads file to server
script extracts any wanted/needed info from the file (name, size, mime-type, checksums, etc...)
start database transaction
insert file info into database
retrieve ID of new record
move uploaded file to final resting place, using the ID as its filename
if everything goes file, commit the transaction
Using the ID as the filename solves the worries of filename collisions and new uploads overwriting previous ones. And if you store the uploads somewhere outside of the site's webroot, then the only access to the files will be via your scripts, providing you with complete control over downloads.