I must create batch file to delete files of a directory which names first symbols are "a". How can I do it?
If you're using Windows try this (assuming *full_path* is directory you want to delete in):
#echo off
DEL /Q full_path\a*.*
or if you want to delete files from that dir and in its subdir, try this:
#echo ff
DEL /Q /S full_path\a*.*
If you're using Linux (or similar), try this:
rm -f full_path/a*
or
rm -rf full_path/a*
If you are using something like Linux or OSX or Cygwin try
find . -name "a*" -delete
If you want to remove whole directories
find . -name "a*" | xargs -n 5 rm -r
Related
I have a batch script that that uses mdpdf. I use the command mdpdf FILE_NAME.md FOLDER/DIFFERENT_FILE_NAME.pdf, and after that I have a few more batch commands. My script looks like this:
mkdir folder
mdpdf filemd.md folder\filepdf.pdf
echo "table{border-collapse:collapse;}table,td,th{border:1px solid black;}" > table.css
pandoc -s filemd.md -c table.css -o ./folder/filehtml.html
del table.css
copy filemd.md export\filemd.md
cd folder
powershell Compress-Archive * Folder-Zip.zip
move Folder-Zip.zip ..\Folder-Zip.zip
cd ..
rmdir /Q /S folder
but after it's done I am left with a foler "folder" and inside a file named "filepdf.pdf". I tried without the mdpdf filemd.md folder\filepdf.pdf and it ended up with a "Folder-Zip.zip" with inside it "filemd.md" and "filehtml.html". What can I do, so I am left with a zip file named "Folder-Zip.zip" with inside of it "filemd.md, filepdf.pdf and filehtml.html"?
I have this script for mounting iso files
#echo off
set fileiso=%~1
set Exedir="C:\Program Files\OSFMount"
cd /d %Exedir%
osfmount -a -t file -f "%fileiso%" -m #:
if the path is like this:(%fileiso%)
D:\Download\another path with some iso inside\Iso\any.iso
not work
any help please :D
This works for me:
#echo off
set "fileiso=%~1"
set Exedir="C:\Program Files\OSFMount"
pushd "%Exedir%"
osfmount -a -t file -f "%fileiso%" -m #:
popd
pause
Output:
C:\Program Files\OSFMount
Creating device...
Created device 1: G: ->
D:\Old C Drive\Users\williamsonm\Downloads\clonezilla-live-20130314-quantal-i386.iso
Notifying applications...
Done.
Press any key to continue . . .
I am more used to using unix shell than CMD, and I am not really sure how to get this to work. I have a directory with several other sub-directories that contain .xml files. I would like to move all the files recursively to the root directory. I know with unix this done like so:
find FOLDERPATH -type f -name '*.xml' -exec mv -i {} FOLDERPATH \;
Yet I can't seem to find something that will work in the same way. XCOPY looked promising, but it doesn't copy only the folders, it copies the whole structure, thus I get these sub-directories that I don't want again. Has anyone got any other suggestions?
This will work from the CMD prompt. Run it in the folder you want the files to be moved to, and it will process the sub-directories in that folder.
It does not provide a mechanism to handle filename collisions elegantly.
for /R /D %f in (*) do move "%f\*.xml" .
and this will work in a batch file.
#echo off
for /R /D %%f in (*) do move "%%f\*.xml" .
Try this:
set FOLDERPATH=...
for /R "%FOLDERPATH%" %%f in (*.xml) do move "%%~ff" "%FOLDERPATH%"
I want to take all of the files in /media/mdrive/dump/:
1COD-234355.jpg
MAK-LXT218.jpg
ZIR-CON145.jpg
And create and sort them into the following directories:
/media/mdrive/dump/1/1COD-234355.jpg
/media/mdrive/dump/M/MAK-LXT218.jpg
/media/mdrive/dump/Z/ZIR-CON145.jpg
How would I do that?
This script takes a directory as the first argument and performs what you need:
#!/bin/bash
DIR="$1"
if [ -z "$DIR" ]; then
echo >&2 "Syntax: $0 <directory>"
exit 1
fi
if [ ! -d "$DIR" ]; then
echo >&2 "\"$DIR\" is not a directory"
exit 1
fi
cd "$DIR"
for file in *.jpg *.JPG; do
first=${file::1}
mkdir -p $first && mv $file $first/;
done
head -c xx will return the first xx characters of its input (here, the filename). mkdir -p will skip directory creation if it already exists.
to make two directories you could try something like
dir "/media/mdrive/dump/1/" :: CD would also work here
mkdir folder 1
mkdir folder 2
from here I think you can continue with your IF statements and so forth.
all you need to do is set the dir commands with the Direct path takes the guess work out.
then to check each just do:
start explorer.exe "the folder's path here"
it should open the folder to view the files
I want to delete all files and folders in a specified folder. The end result should be that the folder is not deleted itself, just empty. In the linux world it is:
rm -rf /home/kasper/*
I have tried del, deltree and rd without luck. They either just delete files or delete everything including the folder itself.
this script inside your folder should solve it:
for /D %%F in (*) do ( rmdir /s/q .\%%~F)
del /q *.*
rmdir /s/q folder
Assuming you are running Windows.
The basic command line tools in Windows are rather limited. However, you can do this and many other tasks easily in PowerShell:
remove-item C:\test\* -recurse
If you prefer the Linux way, you can use UnxUtils, which is a collection of Unix command line tools natively compiled for Windows. I always have these in my PATH.