I'm trying to create a directory tree for a specific set of folders at a certain level. I found how to limit the Tree results using Regular Expressions but I'm unsure as to how I can limit the resulting tree to only say, directories at the first level instead of it finding all sub-directories recursively.
In Linux it's possible to do tree -L 1 to limit results to the first level. How can I do this in Windows cmd?
Example - If my folder directory is as follows:
Folder A
Folder B
Folder C
Folder D
Folder E
I want my tree result to be:
--Folder A
----Folder B
--Folder D
----Folder E
(Only showing 2 levels)
The Tree help is as follows:
Graphically displays the folder structure of a drive or path.
TREE [drive:][path] [/F] [/A]
/F Display the names of the files in each folder.
/A Use ASCII instead of extended characters.
You can't without using some other tool. In an app in C# for instance this would be a few lines of code.
The batch file CDS.bat that is here claims to do what you want. I haven't tested it.
Related
I am writing a spreadsheet that has paths to files.
It will be used in a custom script with some not-well-known software that the company I work at uses. The custom script will read the column in the spreadsheet that has the path + file, in order to find a file residing at that location.
The spreadsheet has path+file entries such as
C:3.jpg
but, usually, in real life, I see a path+file written like this:
C:\3.jpg
Does it matter which way it is written?
Yes. The first means 3.jpg in whatever the current directory is on drive C, while the second means 3.jpg in the root directory of drive C.
In other words, if you're at a command prompt:
C:\Temp>
then C:3.jpg would refer to C:\Temp\3.jpg, while at the prompt
C:\Users\silph>
referring to C:3.jpg would be C:\Users\silph\3.jpg.
On the other hand, at the same two prompts (C:\Temp> and C:\Users\silph>), referring to C:\3.jpg would always refer to the same 3.jpg located in the root of drive C:.
How can I copy a set of files by a specific pattern from a set of deeply structured folders recursively into another folder? Also I need to recreate the folder hierarchy from source folder in the target folder (only that folders, which contain copied files). I need to use standard Windows command-line tools.
This question looks like this one: How can I recursively copy files of a specific pattern into a single flat folder on Windows? ; but in my case I want to keep folder structure, so this script will not do this:
for /r %x in (*.dll, *pdb) do copy "%x" targetDir\
The decision is:
FOR /r %x in (PATTERN) DO
(if not exist TARGET_DIR%~px mkdir TARGET_DIR%~px) & (copy %~x c:\\TARGET_DIR%~px)
So, the "secret" is in %~px command which gives relative path of copied file, so we should create this relative path in target dir.
Suppose folder A contains 2000 files of same type.
I would like to copy 1000 random files from folder A to folder B.
what is the easiest way to do that in Ruby!!
Thanks!
S
Hints :
Dir.entries(<dir>) gives the list of filenames in the given directory as an array.
Array#sample(n) gives you n random elements taken from the array.
FileUtils.cp(<src>, <dest>) helps you copy a file from a dir to another (you need to require fileutils for this though.
I face the following issue in Windows. I have thousands of subfolders in a main folder (let's call it data\ ) and I want to move a big subset of them in another folder (let's call it data2\ ). In a .txt file I have a list of the exact names of the folders that I want to move.
Is there a way to do that with the cmd?
I make a simple example to make the issue more clear. In the folder data\ I have the subfolders A, B, C, D and E. In a text file I have the list of names:
A C E (one name in each line)
I want to move the subfolders A, C and E to the folder data2.
Thanks a lot :)
I suggest using PowerShell instead of plain cmd. You can take advantage of various Linux command aliases. To move the folder data\A to data2\A it is as easy as mv data\A data2. Now you also need to do this as part of a loop, because you have a text file containing the names of all these folders that you would like to move. I am not on a windows system right now, so I can't test the below code. I adapted a for loop that I saw here
$files = cat list.txt
foreach ($f in $files)
{ mv data\$f data2 }
I work on multiple projects, each ~3-5 million lines of code. I have a single tags file at the root of each project. I also have a tools directory shared between all of them.
disk1
|
+--Proj A
|
+--Proj B
|
+--Shared
disk2
|
+--Proj C
|
+--Proj D
When using tags, I would like Vim to first search the tags file at the root of my project, and then search the tags file for Proj X, and then search the tags file in Shared
I can't get Vim to find the tags file in Shared
in my .vimrc file I have:
set tags=tags;D:/Shared
set tags=tags;,D:/Shared (thanks to romainl for catching a missing comma!)
but Vim only searches the local project tags file, not the shared one.
tags; should start at the CWD and traverse back up the tree until a tags file is found (finds the correct one at the project level).
D:/Shared is an explicit path and should find the tags file in that directory but fails to do so (I've checked, it does in fact exist).
I'm using Exuberand Ctags v5.8
set tags=tags;D:/Shared
means "look upward for a tags file from the current directory until you reach D:/Shared".
If you work in project C on disk 2 (let's call that disk E:), Vim will never visit D:/Shared because of two things:
Upward search is not recursive.
If no tags file is found at the root of the "current directory", Vim tries to find one at the root of its parent and so on until it reaches the topmost parent or the directory you specified after the semicolon. So, supposing you are editing E:\ProjectC\path\to\some\file, you can't expect Vim to find a tags file outside of that path. Vim will search for the following tags files, sequentially and, by the way, never find that hypothetic D:\Shared:
E:\ProjectC\path\to\some\tags <-- KO
E:\ProjectC\path\to\tags <-- KO
E:\ProjectC\path\tags <-- KO
E:\ProjectC\tags <-- OK!
E:\tags <-- KO
It won't find any tags file not listed above.
Windows doesn't have the equivalent of UNIX's "root" directory anyway.
When you don't specify a stop directory, upward search climbs the inverted tree of your filesystem from the current directory (or an arbitrary start directory) to the root of the filesystem.
Supposing you are still editing E:\ProjectC\path\to\some\file, upward search will ultimately look for the stop directory D:\Shared directly under every parent directory in the path to E:\ and will rather obviously never find it.
If you want Vim to find D:\Shared\tags wherever you are, you only need to add it explicitely to the tags option. Not as a stop directory but as a specific location:
set tags=tags;,D:/Shared/tags
Now, it says "look upward for a tags file from the current directory and use D:/Shared/tags".
Hmm… that was a lot of words just to explain the need for a single ,.