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

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.

Related

Best practice to parse multiple config files

What would be the best practice - if there is any - to parse multiple config files?
I want to parse the mysql server configuration and also write the configuration again.
The configuration allows to issue multiple lines like:
!includedir /etc/mysql.d/
So the interesting thing is, that some configuration may be located in the main file but other may be located in a sub file.
I think pyparsing only works on ONE single file or one content string.
So I probably first need to read all files and maybe restructures the contents like adding headers for the different files...
====main file====
[mysql]
....
!includedir /etc/mysql.d/
====/etc/mysql.d/my.cnf====
[client]
.....
I would only have one pyparsing call.
Then I could parse everything into one big data object, group the file sections and have the file names as keys. This way I could also write the data back to the disk...
The other possibility would be to parse the main file and programmatically parse all other files that were found in the main file.
Thus I would have several pyparsing calls.
What do you think?
In your pyparsing code, attach a parse action to the expression that matches the include statements, have it parse the contents of the referenced files or directory of files, then merge those results into the current parse output. The parse action would make the successive calls to parseString, your code would only make a single call.
See this new example added to the pyparsing examples directory: https://github.com/pyparsing/pyparsing/blob/master/examples/include_preprocessor.py

How to move files in unix in a way that we save all of the atributes

I had this question in my exam today, I'can't seem to find an answer for it :
how to move all found fit files placed in root and move them in fit directory in a way that we save all atributes?
The question sounds a little vague: the first one and immediate answer is that you use the cp(1) command with --preserve=all. From the manpage:
--preserve[=ATTR_LIST] preserve the specified attributes (default: mode,ownership,timestamps), if possible additional attributes:
context, links, xattr, all
It looks like you're taking an operating systems class though, so I assume that the exam was not testing your ability to know all the possible options to cp(1). The question is (probably) about how to do it in code (or rather, how cp(1) does it).
Programmatically, you could do it like this:
Open the source directory with opendir(3).
Iteratively fetch each entry in the directory with readdir(3). Each call to readdir(3) will return a struct dirent, which, among other things, contains the inode of that entry, the filename, and the type of file (you may want to recursively repeat the process if the file type is a directory)
For each regular file entry, open(2) the file with O_RDONLY. Also open(2) the same filename in the target directory with O_WRONLY | O_CREAT | O_TRUNC (write only mode, truncate the file if it already exists, create it if it doesn't).
Copy the contents as usual with read(2) and write(2).
Call fstat(2) on the source file to get all the attributes.
Call fchmod(2) on the target file to set the permissions to be the same as those in the st_mode field of the stat structure of the source file.
Call fchown(2) on the target file to set the owner and group to be the same as the st_uid and st_gid fields of the stat structure of the source file.
Call futimens(2) on the target file to set the access and modification times to be the same as the st_atime and st_mtime fields of the stat structure of the source file.
Close the file and process the next file.
When done, close the directory with closedir(3).
These are all the attributes that you can preserve in a copy. Note that there are still some differences between the two files:
The ctime (time of last status change, i.e., when the inode was last changed) can't be copied.
The ID of the device containing the file may be different (depending on where you are copying it to).
The inode number is obviously different.
The number of hard links may not be the same.
The file size may differ if the source file had holes in it. Holes in a file are not necessarily backed by disk storage, but if you naively copy byte by byte from the source to target, the destination file will not have holes and will need more disk space.

Overwrite an existing file programmatically

I have a QDialogBox where there is an option to upload a file.
I can upload files and save them to a folder. It works fine.
But if in case there is a file that already exists in the folder, I am not sure how to handle that scenario.
I want to warn the user that the file with same name already exists.
Is there a Windows API that I can use in this case? (because when we manually save an existing file, we get a warning, how can I use that?)
If someone can point me to that documentation, it will be great.
If you are using a QFileDialog, confirmOverwrite is activated by default, so, if getSaveFileName() returned a non-empty QString, then that means the user accepted to overwrite the file. Other way, you get an empty QString.
Then, you can check if the file exists, and remove it in that case, but you know that the user was Ok with that.
There is always a potential race condition when saving files. Checking to see if the file exists first is not safe, because some other process could create a file with the same name in between the check and when you actually write the file.
To avoid problems, the file must be opened with exclusive access, and in such a way that it immediately fails if it already exists.
If you want to do things properly, take a look at these two answers:
How do I create a file in python without overwriting an existing
file
Safely create a file if and only if it does not exist with
python
You can use QDir::entryList() to get the file names in a directory if you're not using a QFileDialog.
QDir dir("/path/to/directory");
QStringList fileNames = dir.entryList();
Then iterating through file names, you can see if there's a file with the same name. If you need it, I can give an example for that too. It'd be C++, but easily adaptable to Python.
Edit: Smasho just suggested that using QDir::exists() method. You can check if the file name exists in the directory with this method instead of iterating like I suggested.
if(dir.exists(uploadedFileName))

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

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?

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.

Resources