Can I concatenate text / html files with some soft of batch file? - osx-snow-leopard

On windows I could do something like...
copy /b file1+file2 file3
copy /b file1+file4 file5
In one batch file to generate a files made up of several files.
I've trying to create some html help files, with a header, footer, unique content and files containing common content.
How can I do this ?

cat file1 file2 >> file3
cat file1 file4 >> file5
file3 and file5 are the output files, just list the files you want to concatenate in order of how they should appear in the output files.

Related

Repeat a specific command for all files located in a folder

I need a script that will go into a directory, execute the command on each file, i tried some commands in a batch file, but i can't figure it out :)
john-wick-parse serialize file_route/filename_with_no_extention
Bash shell for loops
for f in file1 file2 file3 file5
do
echo "We are now processing... $f"
# do something on $f
done
And if you want, you can declare a variable containing the path to the files, one on each line, something like this:
FILES="file1
/path/to/file2
/etc/resolv.conf"
for f in $FILES
do
echo "We are now processing... $f"
# do something on $f
done
There's all sort of options for that, like selecting all files with a certain extension.
So if you were to use the first option:
Our files
-- my_folder
-- file1
-- file2
-- file3
-- etc
Our code
cd /path/to/my_folder
for f in file1 file2 file3 file5
do
echo "We are now processing... $f"
# do something on $f
done

batch file: tree /f is only listing current directory

I wrote a batch file tree.bat with following code:
set output_loc=Z:
set loc=Z:
chdir /d %loc% & tree /f > "%output_loc%\tree.txt"
Let say the drive Z: has following tree
foo1
file1
file3
file3
foo2
file1
file2
tree.bat
foo1
file1
file2
file3
When I run tree.bat I get the following output in Z:\tree.txt
Folder PATH listing for volume storage1
Volume serial number is C508-09ED
Z:.
file1
file2
tree.bat
No subfolders exist
How do I get the whole tree?
Do not name a batch file like any internal or external command! Otherwise, the command interpreter gets confused, like in your case.
The tree command (file name tree.com) you are using is searched in the current directory first, and if not found, it is searched in the directories given by the environment variable PATH. The executable file extensions are taken from environment variable PATHEXT. This all means that the batch file unintentionally tree.bat tries to rerun itself.
In addition, follow MC ND's comment and replace Z: by Z:\ to specify the root directory of drive Z:, as Z: specifies the current directory of the drive, which seems to be Z:\foo2 according to your example (which is the directory containing the batch file).

join files inside every folder using batch command

I have 10-20 directories with a number of files inside in each folder.
I want to join in a single file every pack of files inside each folder so if I have 20 folders with 2300 files I want 20 joined files.
Example
INPUT
folder1 - 500 files
folder2 - 340 files
folder3 - 5 files
OUTPUT REQUEST
folder1.txt (500 joined files)
folder2.txt (340 joined files)
folder3.txt (5 joined files)
But I have many folders so I try to find a .bat command to create automatically this operations.
VIDEO: what i want
Assuming each of your files is text file with a newline terminator at the end of each final line, then you can use the following:
for %%F in ("folder1" "folder2" "folder3") do >"%%F.txt" type "%%~F\*"
The name of each file will be output to the screen via stderr.
If you want to hide the file names:
for %%F in ("folder1" "folder2" "folder3") do >"%%F.txt" 2>nul type "%%~F\*"
If you want the file names to be included in the text file output:
for %%F in ("folder1" "folder2" "folder3") do >"%%F.txt" 2>&1 type "%%~F\*"
IF you want to process all folders within your current directory, then change the FOR command for any of the commands listed above to look like:
for /D %%F in (*) do ...

Batch file to upload each numbered file to a different FTP folder

I need to write a batch file that uploads two files via FTP to different folders.
Example: filename_0001.txt copy to folder1 on server1 filename_0002 copy to folder2 on server1.
The names of target files are fixed.
My current batch file uploads only the first file that has the lower number -the only difference in the filenames are the numbers, that are changed daily.
user name >>script.txt
%1 >>script.txt (password as parameter to batch file)
put filename_????.txt folder1
ftp -s:script.txt [server name]
How can the other file with higher number be uploaded? I thought of checking the file names and then put them in the script. Can anyone tell any command to do that?
I need something like this:
put filename_????+1.txt folder2
Prepare a text file (folders.txt) with a sorted list of folders to use, like:
folderA
folderB
folderC
folderD
From a batch file save a sorted list of files to upload to another file (files.txt). Merge the two files together as described in question Combining multiple text files into one.
The code would be like:
#echo off
dir /ON /B filename_????.txt > files.txt
setlocal EnableDelayedExpansion
3< folders.txt (for /F "delims=" %%a in (files.txt) do (
set /P FOLDER=<&3
echo put %%a !FOLDER!
))
The output will be like:
put filename_4100.txt folderA
put filename_4101.txt folderB
put filename_4102.txt folderC
put filename_4103.txt folderD
It won't work when number of digits in filenames is different, as filename_10000.txt will be sorted before filename_9999.txt. For possible improvement, see Naturally Sort Files in Batch

batch file to search folder for dll file names

I need to write a batch file that will search a folder for all dll's, take their name do some processing with such. So for example a folder containing
File1.dll
File2.dll
File3.dll
within C:\temp
should return
File1
File2
File3
I would like to do some further processing then with these filenames.
Any idea how I might do such?
for /r %i in (*.dll) do #echo %~ni

Resources