How do I exclude a specific file, without excluding every file with an identical name? - textmate2

In TextMate 2's .tm_properties I can exclude a file with a line such as:
exclude = "{index.php}"
However I'd like to exclude such a file in a specific location, not every file with that name.
Obviously, trying /index.php or \/index.php didn't work.

Related

Copying a file, but appending index if file exists

I have several directories with filenames being the same, but their data inside is different.
My program identifies these files (among many others) and I would like to copy all the matches to the same directory.
I am using shutil.copy(src,dst) but I don't want to overwrite files that already exist in that directory (previous matches) if they have the same name. I'd like to be able to append an integer if it already exists. Similar to the behavior in Windows10 when you copy where you can "keep both versions".
So for example, if I have file.txt in several places, the first time it would copy into dst directory it would be file.txt, the next time it would be file-1.txt (or something similar), and the next time it would be file-2.txt.
Are there any flags for shutil.copy or some other copy mechanism in Python that I could use to accomplish this?

Move files to their respective folder in linux based on the date of the folder and the date of the file

I'm fairly new to bash scripting and linux, and I have a folders with just dates such as
2012-11-20
2012-11-21
2012-11-22
2012-11-23
and I have files with the name data_11202012_randomnumbers_csv.
I would like to create a script that can move every single csv file to it's correct folder by matching the date on the file to the folder.
I've been just typing mv file path but i have 100s of files and I'm wondering if theres an easier way.
Any help would be appreciated.
The following should do it for you. I will explain with comments
for file in your_folder/*; do
# 1. Extract the numbers from the file name
dir="${file#data_}" # remove data_ prefix
dir="${dir%%_*}" # remove everything after first _
# 2. Rearrange the numbers into the desired format
dir="${dir:2:4}-${dir:0:2}-${dir:6:2}"
# 3. Move the file into the directory
mv file dir
done
Here you have a very useful bash cheatsheet where you can learn more about it. It illustrates all the variable expansions I've made in my snippet and more.

Node.js - search a file in current working directory, if file not found, traverse up the path up until the first one is found

Example:
User is searching for menu file and currently in C:\Root\Food\Lunch\Pizza.
The menu file is Food folder.
How to traverse up the path to look for it?
You can do it with the basic functions of fs and path modules.
https://nodejs.org/api/fs.html
https://nodejs.org/api/path.html
The easiest way would be to use path.sep to split the current path and remove the last part every time you try a new directory. Or you can remove the parts using a regex, or you can add /.. and use path.normalize() to see the parent dir. There are a lot of ways to do it. Then you can either stat or read the file if you need on every step and stop whenever you see that it exists.

p4 sync, how do you exclude files while using wildcards?

I'm trying to use p4 sync to sync a specific directory to a given changelist number using wildcards but I also want to exclude a list of files that are under that directory (in subdirectories), I tried using - (both before and after using a path with wildcards) but the file never gets excluded, this the command I'm trying:
p4 sync //Repo/Foo/... -//Repo/Foo/Bar/Foobar.txt
The file exclusion seems to only work when the files/directories you are syncing don't match the files you're trying to exclude.
In your client, you would have multiple lines:
//Repo/Foo/... //my_client/Repo/Foo/...
-//Repo/Foo/subdirectory/... //my_client/Repo/Foo/subdirectory/...
This would allow you to get everything in the Foo directory and all subdirectories except "subdirectory".
You can do this if you use a label. Create a label in your favorite editor (p4v or command line p4 label and add your two lines:
//Repo/Foo/...
-//Repo/Foo/Bar/Foobar.txt
In the revision field put "#head" (including quotes!) if you want the latest or a change list number. Give the label a name - for instance "sync_butnot_foobar"
On the command line you can now sync:
p4 sync #sync_butnot_foobar,#sync_butnot_foobar
This has a huge benefit over the modify your client spec and sync head model. If you exclude a file in your client spec, the next time you sync that file will be brought to revision 0 which probably isn't what you wanted.
In short, you can't exclude files on a sync. That can only be done within the client spec. (Well, it could be done through the protections table, but that is really a different matter I think).
But if you want to sync a specific folder and only the files in that folder, use *
p4 sync //Repo/Foo/*
will get you only the files in the Foo folder.

Vim script to switch between header and implementation file using cscope

I currently use the A.vim plugin to swap between header and implementation file. The limitation of this script is that it only works if both are in the same folder.
If you have a cscope database for your code you can easily find the header for a particular implementation file by doing :cscope find f ImplementationFileName.h.
How would you script this to take the current file name without the extension and search for that name with the added .h suffix?
This should be possible out of the box using A.vim. Check out :help alternate-config. Specifically the section on search paths:
b) Search Paths: In many projects the
location of the source files and the
corresponding header files is not
always the same directory. This plugin
allows the search path it uses to
locate source and header files to be
configured. The search path is
specified by setting the
g:alternateSearchPath variable. The
default setting is as follows,
g:alternateSearchPath =
'sfr:../source,sfr:../src,sfr:../include,sfr:../inc'
This indicates that the corresponding
file will be searched for in
../source, ../src. ../include and
../inc all relative to the current
file being switched from. The value of
the g:alternateSearchPath variable is
simply a comma separated list of
prefixes and directories. The "sfr:"
prefix indicates that the path is
relative to the file. Other prefixes
are "wdr:" which indicates that the
directory is relative to the current
working directory and "abs:" which
indicates the path is absolute. If no
prefix is specified "sfr:" is assumed.

Resources