New programmer needs code to open changing filename, delete text and save to same filename - wildcard

I literally know nothing about Perl but am trying to write code to delete characters within a .xml file using Perl 5. Here is what I need to do:
The filename will change every day. For example: MyFile_yyyymmddhrmnsc.xml (where yyyy=year; mm=month; dd=day; hr=hour; mn=minutes; sc=seconds). Using a wildcard to designate what changes each day in the filename: MyFile_*.xml
Within the file, I want to change all instances of "Job xmlns" to "Job"
I want to save the changes to the same XML filename
I hope my explanation is sufficient but if not - please let me know. I realize this might not be the place to ask this - if not, could you please direct me to where I could get information?

Related

Need to handle the spaces between the filename in Control-M File watcher command

I have File watcher job which is looking for certain file name(Membership Daily 20191230.xslx). Could some one share some insights how to handle the space between the file when i provided the path with file name?
Usually will use * as wild card search but i have the different files which are closer with member.
Server File Watcher Run : UNIX
Enclose the full path name in quotation marks (for example, “c:\ctm\My Example.txt”). Only if a file name is in a Rules file containing a wildcard, then the filename should not be enclosed in quotation marks.
If you don't want to use spaces, one ? will wildcard for any one character, for example c:\ctm\My?File?Example.txt.

How to browse through file lines with Julia

I need to browse through a file lines and check if a substring exists inside that line , I need to have the option to go through lines by thier original order..
eachline won't help me from what I understand since I will loose the order,What method should I be using that best fit's my needs ?

How do i store a file for proccessing in asp.net

Path.GetTempFileName is pretty close to what i want. But i wouldnt want to restart the machine and lose these files (as they would be temp). What i need is a unique filename. Whats the best way to do it? I was thinking inserting a key into a db, commit them pulling it but i dont think its a good idea.
I was thinking of using a random number but i am always worried about using random numbers when on a server. Since two request can occur at the same time getting the same number (assuming i dont lock it which would make it slow). So, what can i do?
I plan to use the filename so i can take file(s) from the users post request and save them to a file. Which i then put into a queue to be processed which may be immediately, a second from now or minutes/hours if something has gone wrong.
Store filenames using GUID?
If you are expecting a lot of files. I replace guid dashes to make it into a directory structure.
d524532e-8337-422f-925c-14500972c843.jpg
becomes
\d524532e\8337\422f\925c\14500972c843.jpg
How about a Guid:
var appData = Server.MapPath("~/"App_Data);
var filename = Path.Combine(appData, string.Format("{0}.tmp", Guid.NewGuid()));
or some timestamp or something:
var appData = Server.MapPath("~/"App_Data);
var filename = Path.Combine(appData, string.Format("{0:dd_MM_yyyy_fffff}.tmp", DateTime.Now));

Getting extension of the file in FileUpload Control

At the moment i get file extension of the file like :
string fileExt = System.IO.Path.GetExtension(filUpload.FileName);
But if the user change the file extension of the file ( for example user could rename "test.txt" to "test.jpg" ), I can't get the real extension . What's the solution ?
You seem to be asking if you can identify file-type from its content.
Most solutions will indeed attempt the file extension, but there are too many different possible file types to be reliably identifiable.
Most approaches use the first several bytes of the file to determine what they are.
Here is one list, here another.
If you are only worried about text vs binary, see this SO question and answers.
See this SO answer for checking if a file is a JPG - this approach can be extended to use other file headers as in the first two links in this answer.
Whatever the user renames the file extension to, that is the real file extension.
You should never depend on the file extension to tell you what's in the file, since it can be renamed.
See "how can we check file types before uploading them in asp.net?"
There's no way to get the 'real' file extension - the file extension that you get from the filename is the real one. If file content is your concern, you can retrieve the content type using the .ContentType property and verify that it is a content type that you are expecting - eg. image/jpg.

Send file using Response.BinaryWrite() and delete it afterwards

As part of a Classic ASP Project the user should be able to download a file - which is dynamicly extracted from a zip archive and sent via Response.BinaryWrite() - by simply calling "document.asp?id=[some id here]".
Extracting and sending is not the problem but I need to delete the extracted file after the download finished. I never did any ASP or VBA before and I guess that's why I stuck here.
I tried deleting the file right after Response.WriteBinary() using FileSystemObject.DeleteFile() but this results in a 404-Error on the client-side.
How can I wait till the download finished and then do additional actions?
Edit: This is how my code looks like:
'Unzip a specified file from an archive and put it's path in *document*
set stream = Server.CreateObject("ADODB.Stream")
stream.Open
stream.Type = 1 ' binary
stream.LoadFromFile(document)
Response.BinaryWrite(stream.Read)
'Here I want to delete the *document*
I suspect that the point you are calling the DeleteFile method the file you are trying delete is currently locked by something else, the question is what?
Try including:-
stream.Close()
after your BinaryWrite. Also make sure you've done a similar thing to the component you've used to extract the file. If the component doesn't offer any obviouse "close" methods they trying assigning Nothing to the variables referencing them.
Is it not possible to stream the file into memory, then binary write the stream to the browser, this way the file is never created on the server and there is no need to delete it.
I found a solution: The extracted files are saved in a special directory and everytime a user runs the document.asp it checks this directory for files older than one hour and deletes them.
I think it's the simplest way to manage, but furthermore I would prefer a solution where the document is deleted after downloading.

Resources