How to Delete an Entire Folder with Names Beginning with Numeric Characters - directory

Dear StackOverflow community,
Could you please recommend a batch script to solve the following issue:
There are numerous subfolders in the KApps Folder that begin with numeric characters.
The path is as follows: %LocalAppData%\KApps
1a26745; 2bah257,... are subfolders.
I want to delete all of those subfolders.
Looking forward to receiving your assistance.
I attempted to use this batch script, but it did not work.
#cd /d %LocalAppData%\KApps
for /d %%f in ([0-9]*) do rd /s /q "%%f"

Related

Delete dos folders 4 chars long starting with letter S

I am trying to find a command, which could be described like
rmdir s???
i.e. delete all folders in current dir starting with S, exactly 4 characters long. I've tried rmdir, del, erase, none of them works.
Any ideas please? Will it be different for empty and non-empty folders?
In MS-DOS 6.0 (per your question):
deltree/y s???
And in case you are not in MS-DOS but actually on the Windows command line:
for /f %i in ('dir /a:d /b s????') do rd /s /q %i
I've found something similar to the first answer (in case of empty folders just remove the /s switch)
for /d %n in (s???) do rd /s "%n"

nsis adds empty folders to the installer

The File below:
; Install common files
SetOutPath "${GameDir}\Mopy"
File /r /x "*.bat" /x "*.py*" /x "w9xpopen.exe" /x "Wrye Bash.exe" "Mopy\*.*"
filters out some directories that contain python files but still those directories are created (although empty, or containing empty subdirectories) when I run the installer. Those folders need to be included to the installer (if I get the terminology correct at "compile time") cause the installer has an option to install the python version of the program. I can't come up with a way to not add these empty folders. Is there some wildcard I could use to that purpose or should I go and remove the files on installation (using RMDir ?) ?
I'd say you have two options and one is indeed RMDir if you are OK with it possibly removing empty folders that the user created.
The other option is to not use File /r ... and instead use !system to execute something like a batch file that generates a text file with individual File instructions that you can !include. It would look something like this:
!tempfile files
!system '"mygeneratefilelist.bat" "${files}"'
!include "${files}"
!delfile "${files}"
and the batch file would use FOR and/or DIR to list and ECHO the File commands to %1...

Make zip of directory contents and name zip same as directory - recursively

I have over 500 sub directories coming off of one root directory that each contain >6000 files each. the directories are named 20150218, 20150217, etc., one for each day of the year.
I want to develop a script that will zip all of the files in a directory, i.e. 20150217 and name the directory 20150217.zip. I then want to delete the original files.
so, all of the sud directories in ~/public_html/ispy/dlink/ would be zipped separately.
I appreciate any guidance.
Copy and paste following script into any unix editor (vim, geany, mousepad) and save it in directory with Your "date" subfolders. Name it as you wish, with no extension e.g. zipscript. From terminal: go to directory with Your script, allow to execute it: chmod +x zipscript and fire it: sudo ./zipscript.
#!/bin/bash
for D in *
do
if [ -d "${D}" ]; then
zip -r -j "${D}".zip "${D}"
rm -R "${D}"
fi
done
Script runs as follows: for every file (directory is also a file under unix) in current directory check if it is a directory and, if true, make zip with the same name, then delete subdirectory with all files in it.

Unix- Copying the same file from multiple directories into a new directory while renaming the files

I have 36 subdirectories in the same directory named 10,11,12,....45 and a subdirectory logs
in each subdirectory (except for the directory logs) there is the same file called log.lammps
i was wondering if there was a way where i could copy each log.lammps file from each subdirectory 10-45 and put it in the sub directory logs while also adding the number of the directory that it originated from to the end of the filename
so i am looking for a code that copies the file log.lammps one by one from each subdirectory and every time the file gets copied into the directory logs, the filename gets changed from log.lammps to log.lammps10 if it came from the subdirectory 10 and when the file log.laamps from subdirectory 11 is copied into logs its name changes to log.lammps11 etc.
any help would be appreciated since right now i am only dealing with 30-40 files and in time i will be working with hundreds of files
Something along this line should work:
for f in [0-9][0-9]/log.lammps; do
d=$(dirname ${f})
b=$(basename ${f})
cp ${f} logs/${b}.${d}
done
That's easy-peasy with the magic of shell scripting. I'm assuming you have bash available. Create a new file in the directory that contains these subdirectories; name it something like copy_logs.sh. Copy-paste the following text into it:
#!/bin/bash
# copy_logs.sh
# Copies all files named log.lammps from all subdirectories of this
# directory, except logs/, into subdirectory logs/, while appending the name
# of the originating directory. For example, if this directory includes
# subdirectories 1/, 2/, foo/, and logs/, and each of those directories
# (except for logs/) contains a file named log.lammps, then after the
# execution of this script, the new file log.lammps.1, log.lammps.2, and
# log.lammps.foo will have been added to logs/. NOTE: any existing files
# with those names in will be overwritten.
DIRNAMES=$( find . -type d | grep -v logs | sed 's/\.//g' | sed 's/\///g' | sort )
for dirname in $( echo $DIRNAMES )
do
cp -f $dirname/foo.txt logs/foo$dirname
echo "Copied file $dirname/foo.txt to logs/foo.$dirname"
done
See the script's comments for what it does. After you've saved the file, you need to make it executable by commanding chmod a+x copy_logs.sh on the command line. After this, you can execute it by typing ./copy_logs.sh on the command line while your working directory is the directory that contains the script and the subdirectories. If you add that directory to your $PATH variable, you can command copy_logs.sh no matter what your working directory is.
(I tested the script with GNU bash v4.2.24, so it should work.)
For more on bash shell scripting, see any number of books or internet sites; you might start with the Advanced Bash-Scripting Guide.

Recursively copy files that match a wildcard combination but not create the directory tree in DOS

I found that I can use xcopy /s to copy all files that match a wildcard combination in a folder to another location. But this command re-creates the folder structure. I do not want the tree. I need just the files dumped into the destination folder. There are no duplicate files in the source folder.
You can use for command:
for /R %%x in (*.cpp) do copy "%%x" "c:\dest\"
If you want to run it directly from command prompt (not from a batch file) use %x instead of %%x.
For your purpose, instead of using xcopy you should use robocopy:
http://en.wikipedia.org/wiki/Robocopy
http://technet.microsoft.com/en-us/library/cc733145(WS.10).aspx

Resources