Get parent directory of path in Elisp - directory

I'm trying to find the parent directory of a user-given string str to check if it exists. I can find this easily with (file-name-directory str). My issue is I also want to get the parent directory if they pass something with a trailing slash, like "~/Projects/newdir/" would hopefully get "~/Projects/" spit out instead of "~/Projects/newdir/". I can't seem to find anything like this inside the Emacs documentation.

I believe you are looking for directory-file-name.
See also Walk up the directory tree and Function that returns parent directory absolute path.

Related

"./src/**/*.{html,js}" in tailwindcss's content what does this asterisks mean?

Are this "*" mean anything like "." or ".." when we define path? I am not getting what those means. Why can't I specify the path in the usual way? I wanted to use paths like "../../XYZ" or something like that. But where is this asterisk coming from and what does it mean? Can I define the path in tailwind without using the asterisk?
If anyone can help I would be most glad. I am new to tailwind CSS so a little bit confused. Thank you.
The asteriks are used for dynamic imports for if you want Tailwinds to scan for content in any folder that is under ./src/ (asuming you are using ./src/**/*.{html,js} as content in tailwinds.config.js file. That means if you use ./src/**/*.{html,js}, the first two ** will look for any folder inside ./src, including subfolders.
So, for example, file path in your configuration file will most likely look like:
./src/**/*.{html,js}
./something-else/**/*.{html,js}
And these configured paths will "translate" to something like:
./src/folder1/file.html
./src/folder1/file.js
./src/folder1/subfolder/file.js
./something-else/folder1/file.html
./something-else/folder1/file.js
etc..
Which means if you add a file with the .js or .html extension in the specified folder(s), Tailwinds will automatically include these files in your project.
According to the documentation, you don't want to use really broad path configurations like /**/*.{html,js}' but rather use something like:
./components/**/*.{html,js}
See the Tailwinds content configuration documentation for more examples.
you can use * to match anything except slashes and hidden files,
and use ** to match zero or more directories.
check this site it will help you:
https://tailwindcss.com/docs/content-configuration

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))

skip rules in msdeploy

I am passing several skip arguments to msdeploy in order not to synchronize(Delete and Update) some directories and files
-skip:skipAction='Update',objectName='filePath',absolutePath='.*\\documents\\.*'
It does not seem to work, some directories and files get deleted.
I am pretty sure there's no problem in the regular expression given to the absolutePath
Can anyone please clear up how the matching works for the skip rules?
It is clearly not working according to the regular expression and objectName.
Look here:
http://forums.iis.net/p/1192163/2031814.aspx#2031813
The way skip rules are applied is based on the order of the synchronization operation(delete, update, add) is done on the actual object(directory or file).
For example, if there's a delete operation on the directory, the skip rules for files within the directory for the delete operation will NOT PREVENT files from being get DELETED!
In my case, the directory MySite\MobileForms get deleted entirely. The skip rule I set for the files is useless.
And for the directory, my mistake is in the regular expression:
-skip:skipAction='Delete',objectName='dirPath',absolutePath='.*\\MobileForms\\.*'
Should be:
-skip:skipAction='Delete',objectName='dirPath',absolutePath='.*\\MobileForms$'
which says that it should skip deleting directory path MobileForms(the first rule erroneously included slash in the regular expression).
Hope this helps others as well.

Relative path for a included file - ASP/HTML

Sorry if this question is answered somewhere else but I tried searching several pages and was unsuccessful.
So i have an include file (sidebar) which i am using in all pages.
Default.asp
Products.asp
Salary/Survey.asp
inc/sidebar.asp (this is the included file)
now inside sidebar.asp I have a link for Salary/Survey.asp
from all other pages at root level, i can simply use href='Salary/Survey.asp' and will work fine. but when I am on page Survey.asp , writing href='Salary/Survey.asp' will become actually Salary/Salary/Survey.asp. I understand it has to be ../Salary/Survey.asp to be used properly but it will then not work for root level pages.
I can not use root relative which is /Default.asp and /Salary/Survey.asp as I am working for someone else' project and i dont know his directory structure and thus i only have option to document relative path.
Hope this is clear to understand and someone helps me out.
Thanks!
We solved this problem the following way...
Each of our asp pages included a special file that Dims and sets golbal variables. We called ours Info.asp
Inside Info.asp we defined a variable called strRelativePath
Dim strRelativePath
strRelativePath = ""
Every asp page set the relative path according to it relative position:
for example:
Root pages - strRelativePath = ""
One level deep pages - strRelativePath = "../"
Two levels deep pages - strRelativePath = "../../"
Then it was a matter of prefacing all the links requiring a relative path with <%=strRelativePath%>
you need to get write this after the that - Salary/Survey.asp
You can get the virtual path to the file from one of several server variables - try either:
Request.ServerVariables("PATH_INFO")
Request.ServerVariables("SCRIPT_NAME")
Either server variable will give you the virtual path including any sub-directories and the file name - given your example, you'll get /virtual_directory/subdirectory/file.asp. If you just want the virtual directory, you'll need to strip off everything after the second forward slash using whatever method you prefer for plucking a directory out of a path, such as:
s = Request.ServerVariables("SCRIPT_NAME")
i = InStr(2, s, "/")
If i > 0 Then
s = Left(s, i - 1)
End If
or:
s = "/" & Split(Request.ServerVariables("SCRIPT_NAME"), "/")(1)
basically, if your sidebar can be included from programs in different folders, the only 'easy' way is to use absolute paths like you mentioned.
You say can't use it, so I would think of different ways...
virtual folders: In IIS you could set a virtual folder in salary folder for 'salary' and point it to the site's root.
OS links (similar to above, but at the OS level)
use mappath. You could check mappath to see the actual folder you're in, and use the correct include (with/without /salary) though I'm thinking this might give you an error, not sure.

What does ${imagepath} refer to in a CSS file?

I am trying to adapt a perl script that is used to generate a splash page for a public wifi installation. I was only given a couple example files to work from and no documentation. After several hours on the phone with the access point vendor I was told I could "just edit" the examples in order to design our custom page. I am trying to understand what is going on in the files.
I have .css file with the following in it.
#logo_container {
width: 528px; height: 58px;
background-image: url(${imagepath}body_title_line.gif);
border: 0;
}
I also have a .pl file with a variable $html_body_top containing the following snippet of html:
Acceptable Use Policy
What does the ${imagepath} refer to? Can I get at it?
I guess the root directory of your images. So if body_ title_line.gif is under /images/ the imagePath variable will probably need to reflect this.
CSS does not support variables so this is something injected by your PL script.
It's possible that's a variable substituted by Template Toolkit, not by your Perl script.
It's also possible the Perl script isn't using strict and, due to lack of declaration of the variable, is substituting a blank string in place of ${imagepath}.
Looks like a token that will be replaced by some sort of build script that runs over all the files in the project.
I would guess that imagepath is a variable from the perl script, replaced at generation time with the actual URL.
Looks like the perl script needs to be run with some value of $imagepath.
${imagepath} is equal to the variable $imagepath. The braces are generally used when variables are used in a string, to remove ambiguity

Resources