For a project I received 700 folders with names of institutions (containing spaces).
The purpose is now to create subfolders in each of these folders.
[institution folder]\Documents\
[institution folder]\Images\
[institution folder]\Videos\
According some posts here the below script should work to create the Documents folder
FOR /d %A IN (C:\Users\myname\project\institutions\*) DO mkdir %A\Documents
However, I notice in the feedback that I get from the command line that this instruction fails at the spaces in the foldername. How can I get this to work?
FOR /d %A IN (C:\Users\myname\project\institutions\*) DO mkdir "%A"\Documents
should do the trick.
make sure you wrap expressions containing spaces with " to make sure the shell sees them as a single entity.
Related
Question: In Git Bash on windows, how would you run the following in a way that it will also search folders with spaces in the name, and execute on files with spaces in the name?
$ find ./ -type f -name '*.png' -exec sh -c 'cwebp -q 75 $1 -o "${1%.png}.webp"' _ {} \;
Context I'm running Git Bash on windows, trying to execute a command on all found .png files to convert them to .webp format. It works for all files without spaces in the path, but it's failing to find files with spaces in the filename or files within folders that have spaces in the folder name.A few considerations:
I have many, many levels of folders to iterate through, and I can't run this command separately for each. I really need the recursion to work.I cannot change the folder names; it will break other dependencies (nor did I create the folder or filenames originally, so cut me some slack!)I arrived here by following the suggestions from this article: https://www.smashingmagazine.com/2018/07/converting-images-to-webp/the program, to my knowledge, doesn't ship with any built-in recursive command... golly that'd be handy
Any help you can provide will be appreciated. Thanks!
I want to copy many text files from one folder to another. The file names are contained in another text file. So the commands should be able to read in the file names and do the copy things. I can do this with R but it's very slow. I wonder if it's possible to do this with the command line? (I can copy single file with the command line, but don't know how to copy many with for or while loop or something.) Thanks in advance.
I found this question helpful: How do you loop through each line in a text file using a windows batch file?
This is what you need to just paste into the command line. If you want to save it in a bash file you need to use %% instead of % for variables.
for /F "tokens=*" %a in (myfile.txt) do copy "%a" "new folder\%a"
This simply loops through the file, and for each line does a copy of it to the new folder. The quotes are important in case of spaces in the filenames.
if i copy without space (Name Folder),
example:
xcopy /E C:\Test\SQL G:\SQL
this copy all content of my folder, Fine!
i dont know how to copy folder if name contain a space, With "xcopy" command.
i found many reviews about space in command prompt and show me solutions like
c:\>xcopy /E "c:\Documents\SQL Server Management\" "G:\SQL\"
but doesn't work for me.
if I copy a folder where the name contains spaces, the result is: Invalid number of parameters...
Any can help me ?
Tnhks
You should report the error message you are receiving, what happened when you executed he command (if anything) and what you expected to happen.
Your problem is that copy requires a filemask to know which files you require to be copied.
c:>xcopy /E "c:\Documents\SQL Server Management*.*" "G:\SQL\"
specifies that all files with all extensions be copied. The quotes are required to specify "paths\containing spaces" as xcopy (or any other command has no way of reading your mind and can't be certain of what c:\Documents\SQL Server Management\ G:\SQL\ means - is it 'copy c:\Documents\SQL to "Server Management\ G:\SQL\"' or 'copy "c:\Documents\SQL Server" to "Management\ G:\SQL\"' or are sume of what appear to be arguments strays data or what?
Here's the question:
set Pathname = C:\Program Files
cd %Pathname%
pause
The above doesn't change the directory, as I would expect. Can anybody please tell me why?
The set statement doesn't treat spaces the way you expect; your variable is really named Pathname[space] and is equal to [space]C:\Program Files.
Remove the spaces from both sides of the = sign, and put the value in double quotes:
set Pathname="C:\Program Files"
Also, if your command prompt is not open to C:\, then using cd alone can't change drives.
Use
cd /d %Pathname%
or
pushd %Pathname%
instead.
simple way to do this... here are the example
cd program files
cd poweriso
piso mount D:\<Filename.iso> <Virtual Drive>
Pause
this will mount the ISO image to the specific drive...use
I have a Perl script that needs to delete a directory with all its contents.
Sometimes this directory contains a junction point into another directory. If I rmtree() naively, the rmtree() call will also delete all the files inside the target folder of the junction. I'm looking for a way to not do that, and instead just remove the junction.
Non Perl solutions would also be appreciated.
I just typed "junction point" into Google and found my way to
http://en.wikipedia.org/wiki/NTFS_junction_point
Command Prompt (cmd.exe)
The dir
command in Windows 2000 or later
recognizes junction points, displaying
instead of in
directory listings (use dir with the
/A or /AL command-line switch).
Any
commands that would normally affect
files inside a normal directory will
act the same here. Thus the command
del myjunction should not be used —
this will just delete all the files in
the targeted directory.
The commands
rmdir and move work fine with
junctions, with the caveat that move
won't let the junction move to another
volume (as opposed to Windows
Explorer, as mentioned above.)
The
rmdir command is safe in that it only
deletes the junction point, not the
targeted files. Whilst walking through
the directory with the command line
interface, files can be deleted, but
unlike explorer, directories can also
be deleted (using rmdir /s dirname for
example.)
Using the linkd command with
the /d switch is a safe way to delete
junction points.
From what I can see you can, for example, use dir and grep the output for <JUNCTION> or use the Windows rmdir. I think you can use either of these from Perl via system.
To find out where are the reparse points (or "junction points", if you will):
dir /a:l /b > myjunctions.txt
Will show all reparse points in the current directory. You can add /s, but beware that reparse points inside reparse points will be listed as well.
Suppose myjunctions.txt contains the line x:\subdir\foo. To remove it, you issue
fsutil reparsepoint "x:\subdir\foo"
And voilá! Your junction point is gone, and the original directory is untouched!
FastCopy utility does this: http://ipmsg.org/tools/fastcopy.html.en
I am using this program for copying or deleting folders that may contain junctions as subfolders so that the junction targets remain untouched. The junction points are properly copied while copying, even when the target drive is different.
Windows Explorer at least in Windows 7 Ultimate works also as wanted while deleting - junction targets remain intact.
But copying folders that contain junctions as subfolders in Explorer still does not work as intended - it actually does something that I cannot yet perhaps quite entirely describe: the junction folders seem to be copied as normal folders, but their content is empty.