I would like to convert a large number of html files to txt files. I have downloaded the inscript command line tool from github but I am struggling to apply it to all html files which are located in subdirectories and then save these files as text files in the same directory where the html files are located.
I have tried:
for f in ./ do inscript.py -o test.txt done
The following should work:
for d in ./**/*/; do
pushd "$d"
for f in *.html(N); do
out=test-${f%.html}.txt
inscript.py -o "$out" "$f"
done
popd
done
The pattern .**/*/ will recursively match the current directory and all its subdirectories. pushd will change to a directory, but remember the current working directory. inscript.py does its thing, then popd returns to the original working directory so that the next value of d continues to be a valid
relative directory.
Changing the working directory isn't strictly necessary; it just simplifies the file paths involved, because you focus on the name of the file and ignore the rest of the path.
Related
I want to create a batch/shell script for windows and mac that will take few different files with different types and will compress it to a .zip file.
I already saw a few questions and answers about it, but all of them either compress all the files in the folder or compress them individually.
Example (look at attached image):
I have a folder that contains 1.txt, 2.xml, a sub directory.
And I want to turn all of them into a .zip file.
If possible to get a solution both for windows and Mac.
On Windows there is the file 7zip.chm in directory %ProgramFiles%\7-Zip which is the help file of 7-Zip. Double click on this file to open the help.
On Contents tab there is the list item Command Line Version with the help pages:
Syntax ... Command Line Syntax
Commands ... Command Line Commands
Switches ... Command Line Switches
The target is to compress everything in folder test into a ZIP file with name of the folder as file name.
This could be done for example with the command line:
"%ProgramFiles%\7-Zip\7z.exe" a -bd -mx=9 -r -y -- test.zip "C:\Path to Directory\test\*"
This command line adds (a) everything in directory C:\Path to Directory\test recursive (-r) to a ZIP file with name test.zip in current working directory without progress indicator (-bd) using best ZIP compression (-mx=9) with assuming Yes on all queries (-y).
In other words the file test.zip in current directory contains after execution the subdirectory main with everything inside and the files 1.txt and 2.xml.
I have a list of absolute file paths as shown below. This list includes 1000's of files in different directories and some of the files are missing. I want to know which files are missing. How can we do this in unix?
list of files:
files.txt
/filpath1/file.bam
/filespath2/file2.bam
/filepath3/file3.bam
This will probably work (it fails if any of the files contain embedded new lines, amongst other possible failure scenarios):
while read path; do
test -e "$path" || echo "$path" does not exist
done < files.txt
I want to delete two specific folders and a file from my current directory:
1. settings/
2. models/
3. file.txt
How do I remove these using single command in terminal?
rm -rf settings/ models/ file.txt
The solution provided by #jcpennypincher is correct for unix system since folders are functionally treated like files.
r stand for "recursive": delete files in directory and in its subdirectories and in its subdirectories etc...,
f stand for "force".
man rm
If you are looking for the same solution in windows (command prompt) it can't be done in just one command: files and folder in windows have different rappresentations. You have to use del for files and rmdir command for folders.
I need to get all files that are inside a dir including files that are inside all dirs.
I found this post that gets all files of the dir, but it is for the current level files and don't goes any deeper.
Maybe there is already a built-in function to do this?
To list all files in the current directory and sub-directories, use:
dir /s
I'm trying to copy a number of files from a directory. I want to include the file path from the base of this particular directory tree, however, I only have a list of the file names to go by. Is there a way to copy either:
a list of files with their directories appended to the beginning in a .txt file
a copy of the folders in the directory with copies of the files placed in their original places in the original directory.
Each file in the directory has a unique name.
I've looked all over google, but the closest I've found is xcopy, which I don't believe is capable of this.
Thanks!
For the second option you can use xcopy /s or robocopy /s. Both are great tools for this kind of job.