Delete dos folders 4 chars long starting with letter S - wildcard

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"

Related

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

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"

Run uic for all .ui files in directory using windows batch

I can get a list of Qt .ui files like so:
D:\programing\qtproject\ui\designer>dir *.ui /B
main.ui
mainmenu.ui
mainwindow.ui
And what I do right now is that I manually run uic for every one of them, because IDE I'm using (QtCreator, ironically the one IDE that should be perfectly compatible with Qt) is not capable of that.
So can I run uic with a list of files obtained from dir *.ui /B? I would prefer if this worked recursively on all subdirectories.
Ok, I cracked it using some helpful answers:
#echo off
rem Runs uic command over all files in all subdirectories
rem For loop arguments explained here: http://stackoverflow.com/a/3433012/607407
rem start command arguments explained here: http://stackoverflow.com/a/154090/607407
rem /B is why the start creates no additional windows: http://stackoverflow.com/a/324549/607407
for /f %%F in ('dir *.ui /S /B') do start "" /B "uic" %%F -o %%~dpFui_%%~nF.h
To disable the recursion (subdirectories), remove the /S parameter in the dir command.

Recursively search for a file name and copy in MS DOS

I have a text file containing names of files separated by newline and a folder with many sub folders which would contain the files matching with names in text file.
I want to pick file names from text file which can be done using for loop; and recursively search for file name in the folder and if the file is found copy it to a different location.
Can anyone please shed a light on it?
Thanks,
#echo off
for /f "usebackq delims=" %%a in ("file names.txt") do (
for /f "delims=" %%b in (' dir "c:\folder\%%a" /b /s /a-d ') do (
copy "%%b" "c:\new folder"
)
)
Very easy (though you'll have to a bit more specific so you can tweak the code to suit your situation.
Base Code:
#echo off
for /f "usebackq tokens=*" %%a in ("file names.txt") do (
forfiles /p "C:\users\...[path to main file]" /s /m "%%a" /c "cmd /c copy #path "C:\users\...[target path]""
Not sure if the above double quotes will stuff up, if it does then we can replace with a call and enableextensions.
Tell me if that doesn't work (since it will only work on Win7). Because there are many other ways to do it.
Mona

IIS 7 Log Files Auto Delete?

Is there any feature in IIS 7 that automatically deletes the logs files older than a specified amt of days?
I am aware that this can be accomplished by writing a script(and run it weekly) or a windows service, but i was wondering if there is any inbuilt feature or something that does that.
Also, Currently we turned logging off as it is stacking up a large amount of space. Will that be a problem?
You can create a task that runs daily using Administrative Tools > Task Scheduler.
Set your task to run the following command:
forfiles /p "C:\inetpub\logs\LogFiles" /s /m *.* /c "cmd /c Del #path" /d -7
This command is for IIS7, and it deletes all the log files that are one week or older.
You can adjust the number of days by changing the /d arg value.
One line batch script:
forfiles /p C:\inetpub\logs /s /m *.log /d -14 /c "cmd /c del /q #file"
Modify the /d switch to change number of days a log file hangs around before deletion. The /s switch recurses subdirectories too.
Ref: http://debug.ga/iis-log-purging/
Similar solution but in powershell.
I've set a task to run powershell with the following line as an Argument..
dir D:\IISLogs |where { ((get-date)-$_.LastWriteTime).days -gt 15 }| remove-item -force
It removes all files in the D:\IISLOgs folder older than 15 days.
Another viable Powershell one-liner:
Get-ChildItem -Path c:\inetpub\logs\logfiles\w3svc*\*.log | where {$_.LastWriteTime -lt (get-date).AddDays(-180)} | Remove-Item -force
In case $_.LastWriteTime doesn't work, you can use $PSItem.LastWriteTime instead.
For more info and other suggestions to leverage the IIS LogFiles folder HDD space usage, I also suggest to read this blog post that I wrote on the topic.

`(cd X; pwd)` sometimes returns two-line

I have shell script which starts with:
sdir=`dirname $0`
sdir=`(cd "$sdir/"; pwd)`
And this usually gets expanded (with 'sh -h') into
++ dirname /opt/foo/bin/bar
+ sdir=/opt/foo/bin
++ cd /opt/foo/bin/
++ pwd
+ sdir=/opt/foo/bin
but for single user for single combination of parameters in expands into (note two lines at the result sbin value)
++ dirname bin/foo
+ sdir=bin
++ cd bin/
++ pwd
+ sdir='/opt/foo/bin
/opt/foo/bin'
I tried different combinations but was not able to reproduce this behavior. With different input parameters for that user it started producing correct single line result. I am new to shell scripting, so please advice when such (cd X; pwd) can return two line.
it was observed on CentOS, but not sure it that matters. Please advice.
The culprit is cd, try this instead
sdir=`dirname $0`
sdir=`(cd "$sdir/" >/dev/null; pwd)`
This happens because when you specify a non absolute path and the directory is found in the environment variable CDPATH, cd prints to stdout the value of the absolute path to the directory it changed to.
Relevant man bash sections:
CDPATH The search path for the cd command. This is a
colon-separated list of directories in which the
shell looks for destination directories specified
by the cd command. A sample value is ``.:~:/usr''.
cd [-L|-P] [directory]
Change the current working directory to directory. If
directory is not given, the value of the HOME shell
variable is used. If the shell variable CDPATH exists,
it is used as a search path. If directory begins with a slash,
CDPATH is not used.
The -P option means to not follow symbolic links; symbolic
links are followed by default or with the -L option. If
directory is ‘-’, it is equivalent to $OLDPWD.
If a non-empty directory name from CDPATH is used, or if ‘-’
RELEVANT -\ is the first argument, and the directory change is successful,
PARAGRAPH -/ the absolute pathname of the new working directory is written
to the standard output.
The return status is zero if the directory is successfully
changed, non-zero otherwise.
OLDPWD The previous working directory as set by the cd
command.
CDPATH is a common gotcha. You can also use "unset CDPATH; export CDPATH" to avoid the problem in your script.
It's possible that user has some funky alias for "cd". Perhaps you could try making it do "/usr/bin/cd" (or whatever "cd" actually runs by default) instead.
Some people alias pwd to "echo $PWD". Also, the pwd command itself can either be a shell built-in or a program in /usr/bin. Do an "alias pwd" and "which pwd" on both that user and any user that works normally.
Try this:
sdir=$( cd $(dirname "$0") > /dev/null && pwd )
It's just a single line and will keep all special characters in the directory name intact. Remember that on Unix, only two characters are illegal in a file/dir name: 0-byte and / (forward slash). Especially, newlines are valid in a file name!

Resources