<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>batでファイル作成 &#8211; スグブログ</title>
	<atom:link href="https://sugublog.org/tag/bat%E3%81%A7%E3%83%95%E3%82%A1%E3%82%A4%E3%83%AB%E4%BD%9C%E6%88%90/feed/" rel="self" type="application/rss+xml" />
	<link>https://sugublog.org</link>
	<description>ブログ運営について発信中</description>
	<lastBuildDate>Sun, 18 Feb 2024 10:14:42 +0000</lastBuildDate>
	<language>ja</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>

<image>
	<url>https://sugublog.org/wp-content/uploads/2021/07/icon_20210703-min-150x150.png</url>
	<title>batでファイル作成 &#8211; スグブログ</title>
	<link>https://sugublog.org</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>【bat基礎】バッチでファイルを簡単に作成する方法！全３種類ご紹介</title>
		<link>https://sugublog.org/bat-file-create/</link>
					<comments>https://sugublog.org/bat-file-create/?noamp=mobile#respond</comments>
		
		<dc:creator><![CDATA[suguru]]></dc:creator>
		<pubDate>Sun, 21 May 2023 12:15:42 +0000</pubDate>
				<category><![CDATA[bat]]></category>
		<category><![CDATA[batでファイル作成]]></category>
		<guid isPermaLink="false">https://sugublog.org/?p=5523</guid>

					<description><![CDATA[<p><img src="https://sugublog.org/wp-content/uploads/2021/08/DB0804-3-1024x717.jpg" class="webfeedsFeaturedVisual" /></p>batファイルでファイルを作成する方法をお伝えします。 ファイルを何個も作成する場合に、batで行えば楽に業務を遂行する事が可能です。 batでファイルを簡単に作成する方法 batでファイルを作成する方法は3つあります。 [&#8230;]]]></description>
										<content:encoded><![CDATA[<p><img src="https://sugublog.org/wp-content/uploads/2021/08/DB0804-3-1024x717.jpg" class="webfeedsFeaturedVisual" /></p>
<p>batファイルでファイルを作成する方法をお伝えします。</p>



<p>ファイルを何個も作成する場合に、batで行えば楽に業務を遂行する事が可能です。</p>


<div class="p-blogParts post_content" data-partsID="5030">
<p>windowsのプロンプトで使用できるbatやpythonやphpを使用して、業務効率化やWebサイトを作成しております。javaやシェルスクリプトなど、様々なプログラミングを行った実績ありの筆者です。</p>
</div>


<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-9330904718533231"
     crossorigin="anonymous"></script>
<ins class="adsbygoogle"
     style="display:block"
     data-ad-format="autorelaxed"
     data-ad-client="ca-pub-9330904718533231"
     data-ad-slot="8455594968"></ins>
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script>



<h2 class="wp-block-heading">batでファイルを簡単に作成する方法</h2>


<div class="wp-block-image">
<figure class="aligncenter size-large"><img decoding="async" width="1024" height="768" src="https://sugublog.org/wp-content/uploads/2021/08/DB0804-1-1024x768.jpg" alt="ファイル作成" class="wp-image-3840" srcset="https://sugublog.org/wp-content/uploads/2021/08/DB0804-1-1024x768.jpg 1024w, https://sugublog.org/wp-content/uploads/2021/08/DB0804-1-300x225.jpg 300w, https://sugublog.org/wp-content/uploads/2021/08/DB0804-1-768x576.jpg 768w, https://sugublog.org/wp-content/uploads/2021/08/DB0804-1.jpg 1200w" sizes="(max-width: 1024px) 100vw, 1024px" /></figure>
</div>


<p>batでファイルを作成する方法は3つあります。</p>



<div class="swell-block-capbox cap_box is-style-onborder_ttl"><div class="cap_box_ttl"><span>batでファイルを作成する方法３選</span></div><div class="cap_box_content">
<ul class="wp-block-list">
<li>echoを使用してファイルを作成する方法</li>



<li>typeを使用してファイルを作成する方法</li>



<li>copyを使用してファイルを作成する方法</li>
</ul>
</div></div>



<p>一つ一つ説明します。</p>



<h2 class="wp-block-heading">echoを使用してファイルを作成する方法</h2>



<p><span class="swl-marker mark_orange"><strong>batファイル</strong>で<strong>「echo」コマンド</strong>と言えば文字を表示するコマンドです。それを使用して<strong><span class="swl-inline-color has-swl-deep-01-color">ファイルを作成</span></strong>します。</span></p>



<p class="is-style-icon_pen">echoコマンドの使い方基礎は、以下の記事で纏めています。</p>


<div class="swell-block-postLink">			<div class="p-blogCard -external" data-type="type1" data-onclick="clickLink">
				<div class="p-blogCard__inner">
					<span class="p-blogCard__caption">スグブログ</span>
					<div class="p-blogCard__thumb c-postThumb"><figure class="c-postThumb__figure"><img decoding="async" src="https://sugublog.org/wp-content/uploads/2021/07/html-007-2-scaled.jpg" alt="" class="c-postThumb__img u-obf-cover" width="320" height="180"></figure></div>					<div class="p-blogCard__body">
						<a class="p-blogCard__title" href="https://sugublog.org/bat-base-echo/" target="_blank" rel="noopener noreferrer">【bat基礎】バッチファイルのechoで文字列表示する！エラー対処法あり | その他のやり方も必見！</a>
						<span class="p-blogCard__excerpt">batファイルで「echo」の使い方を今回は行います。 「echo」コマンドは指定の文字列を標準出力に表示する事が出来るコマンドです。 ただ文字列を表示するだけでなく、ファ&#8230;</span>					</div>
				</div>
			</div>
		</div>


<p>以下のようなbatファイルを作成します。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-c" data-file="file_create.bat" data-lang="C"><code>@echo off
REM echoでファイル作成
echo テストファイル &gt; testfile.txt</code></pre></div>



<p class="is-style-dent_box">@echo offはコマンド自体を非表示にするコマンドです。詳しくは以下の記事を参照ください。</p>


<div class="swell-block-postLink">			<div class="p-blogCard -internal" data-type="type1" data-onclick="clickLink">
				<div class="p-blogCard__inner">
					<span class="p-blogCard__caption">あわせて読みたい</span>
					<div class="p-blogCard__thumb c-postThumb"><figure class="c-postThumb__figure"><img decoding="async" src="https://sugublog.org/wp-content/uploads/2021/12/PC教室20211216-8-300x229.jpg" alt="" class="c-postThumb__img u-obf-cover" width="320" height="180"></figure></div>					<div class="p-blogCard__body">
						<a class="p-blogCard__title" href="https://sugublog.org/bat-echo-off/">【bat基礎】バッチで「@echo off」の意味や効果とは？</a>
						<span class="p-blogCard__excerpt">batファイルの初めに「@echo off」という記載があると思いますが、この意味は何でしょうか？ なんの効果があるのでしょうか？「@echo off」が無ければどうなるのでしょ&#8230;</span>					</div>
				</div>
			</div>
		</div>


<p class="is-style-dent_box">REMはコメントアウトするコマンドです。詳しくは以下の記事を参照ください。</p>


<div class="swell-block-postLink">			<div class="p-blogCard -internal" data-type="type1" data-onclick="clickLink">
				<div class="p-blogCard__inner">
					<span class="p-blogCard__caption">あわせて読みたい</span>
					<div class="p-blogCard__thumb c-postThumb"><figure class="c-postThumb__figure"><img decoding="async" src="https://sugublog.org/wp-content/uploads/2021/07/analytics-6-300x200.jpg" alt="" class="c-postThumb__img u-obf-cover" width="320" height="180"></figure></div>					<div class="p-blogCard__body">
						<a class="p-blogCard__title" href="https://sugublog.org/bat-rem-meen-and-use/">【bat基礎】remの意味と使い方を教えます！初心者向けの記事になります！</a>
						<span class="p-blogCard__excerpt">batファイルでremという文字を見かけるけど、どういった意味があるのでしょうか？ どのような時に使用するのでしょうか？使い方は？ といった疑問の声がありましたので&#8230;</span>					</div>
				</div>
			</div>
		</div>


<p class="is-style-dent_box">REM以外でコメントアウトする方法や推奨するコメントアウトのやり方などは以下の記事を参照ください。</p>


<div class="swell-block-postLink">			<div class="p-blogCard -internal" data-type="type1" data-onclick="clickLink">
				<div class="p-blogCard__inner">
					<span class="p-blogCard__caption">あわせて読みたい</span>
					<div class="p-blogCard__thumb c-postThumb"><figure class="c-postThumb__figure"><img decoding="async" src="https://sugublog.org/wp-content/uploads/2021/07/PC007-8-300x182.jpg" alt="" class="c-postThumb__img u-obf-cover" width="320" height="180"></figure></div>					<div class="p-blogCard__body">
						<a class="p-blogCard__title" href="https://sugublog.org/bat-commentout/">【bat基礎】バッチファイルでコメントアウトする方法！【エラー対処法有り】</a>
						<span class="p-blogCard__excerpt">batファイルでコメントアウトしたい場合の方法を記入します。 スクリプトを作成する上でコメントアウトは大事ですよね。後から見たら何をしているのかわからなくなった&#8230;</span>					</div>
				</div>
			</div>
		</div>


<p><strong>「echo」コマンドで表示したい文字を表示します。</strong></p>



<p>それを<span class="swl-marker mark_orange"><strong>リダイレクトしテキストファイル名を指定</strong>すれば、<strong><span class="swl-inline-color has-swl-deep-01-color">batでファイルを作成する事が可能</span></strong></span>です。</p>



<p>中身に「テストファイル」と書かれた「testfile.txt」ファイルが作成されます。</p>



<h2 class="wp-block-heading">typeを使用してファイルを作成する方法</h2>



<p><strong><span class="swl-marker mark_yellow">batファイルで「type」コマンド</span></strong>とは、ファイルの中身を表示するコマンドです。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-c" data-file="file_create.bat" data-lang="C"><code>@echo off
REM typeでファイル作成
type NUL &gt; nul_testfile.txt</code></pre></div>



<p><strong>「type」コマンドでNULを指定</strong>します。</p>



<p class="is-style-icon_pen">「NUL」とは何もない空の事になります</p>



<p>それを<strong><span class="swl-marker mark_yellow">リダイレクトしてファイル名を指定</span></strong>します。</p>



<p>すると指定した名前の<span class="swl-bg-color has-swl-deep-02-background-color">空ファイルが作成</span>されます。</p>



<h2 class="wp-block-heading">copyを使用してファイルを作成する方法</h2>



<p>「copy」コマンドはファイルなどをコピーするコマンドです。</p>



<p>この「copy」コマンドでもbatでファイルを作成する事が可能です。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-c" data-file="file_create.bat" data-lang="C"><code>@echo off
REM copyでファイル作成
copy NUL copy_nul_testfile.txt
</code></pre></div>



<p>「type」コマンドと同様に<strong>「NUL」を指定</strong>します。</p>



<p><span class="swl-marker mark_green">リダイレクトを行いファイル名を指定</span>します。</p>



<p>すると<strong><span class="swl-inline-color has-swl-deep-01-color">「copy」コマンドで空のファイルを作成する事が可能</span></strong>です。</p>



<script async="" src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<ins class="adsbygoogle ads" style="display:block; text-align:center;" data-ad-layout="in-article" data-ad-format="fluid" data-ad-client="ca-pub-9330904718533231" data-ad-slot="6086594686"></ins>
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script>


<div class="p-blogParts post_content" data-partsID="6113">
<div class="wp-block-columns">
<div class="wp-block-column">
<a href="https://px.a8.net/svt/ejp?a8mat=3TNJ87+8UIXF6+5EPG+65U41" rel="nofollow">
<img decoding="async" border="0" width="250" height="250" alt="" src="https://www29.a8.net/svt/bgt?aid=231205399535&#038;wid=001&#038;eno=01&#038;mid=s00000025234001035000&#038;mc=1"></a>
<img decoding="async" border="0" width="1" height="1" src="https://www18.a8.net/0.gif?a8mat=3TNJ87+8UIXF6+5EPG+65U41" alt="">
</div>



<div class="wp-block-column">
<a href="https://px.a8.net/svt/ejp?a8mat=3HP27C+14HHWY+3XAE+69P01" rel="nofollow">
<img decoding="async" border="0" width="300" height="250" alt="" src="https://www27.a8.net/svt/bgt?aid=211121256068&#038;wid=001&#038;eno=01&#038;mid=s00000018311001053000&#038;mc=1"></a>
<img decoding="async" border="0" width="1" height="1" src="https://www11.a8.net/0.gif?a8mat=3HP27C+14HHWY+3XAE+69P01" alt="">
</div>
</div>
</div>


<h2 class="wp-block-heading">まとめ：batでファイルを作成する方法</h2>


<div class="wp-block-image">
<figure class="aligncenter size-large"><img decoding="async" width="1024" height="682" src="https://sugublog.org/wp-content/uploads/2021/11/DB_1114-5-1024x682.jpg" alt="ファイル作成" class="wp-image-4502" srcset="https://sugublog.org/wp-content/uploads/2021/11/DB_1114-5-1024x682.jpg 1024w, https://sugublog.org/wp-content/uploads/2021/11/DB_1114-5-300x200.jpg 300w, https://sugublog.org/wp-content/uploads/2021/11/DB_1114-5-768x511.jpg 768w, https://sugublog.org/wp-content/uploads/2021/11/DB_1114-5.jpg 1200w" sizes="(max-width: 1024px) 100vw, 1024px" /></figure>
</div>


<p>batでファイルを作成する方法は以下の３つです。</p>



<div class="swell-block-capbox cap_box is-style-onborder_ttl"><div class="cap_box_ttl"><span>batでファイルを作成する方法３選</span></div><div class="cap_box_content">
<ul class="wp-block-list">
<li>echoを使用してファイルを作成する方法</li>



<li>typeを使用してファイルを作成する方法</li>



<li>copyを使用してファイルを作成する方法</li>
</ul>
</div></div>



<p>それぞれの実際のコードは以下に示しています。</p>



<div class="hcb_wrap"><pre class="prism line-numbers lang-c" data-file="file_create.bat" data-lang="C"><code>@echo off
REM echoでファイル作成
echo テストファイル &gt; testfile.txt

REM typeでファイル作成
type NUL &gt; nul_testfile.txt

REM copyでファイル作成
copy NUL copy_nul_testfile.txt</code></pre></div>



<h2 class="wp-block-heading">実践：batでファイルを作成する</h2>



<p>では<span class="swl-marker mark_blue"><strong>実際にこのbatファイルを実行</strong></span>してみましょう。</p>


<div class="swell-block-postLink">			<div class="p-blogCard -internal" data-type="type1" data-onclick="clickLink">
				<div class="p-blogCard__inner">
					<span class="p-blogCard__caption">あわせて読みたい</span>
					<div class="p-blogCard__thumb c-postThumb"><figure class="c-postThumb__figure"><img decoding="async" src="https://sugublog.org/wp-content/uploads/2021/07/analytics-2-300x157.jpg" alt="" class="c-postThumb__img u-obf-cover" width="320" height="180"></figure></div>					<div class="p-blogCard__body">
						<a class="p-blogCard__title" href="https://sugublog.org/bat-execution/">【bat】バッチを実行する方法！実行できない時の対処法などをご紹介</a>
						<span class="p-blogCard__excerpt">batファイルが既にありそれを実行してと言われたけど、どうやって実行すればわからない人の悩みに答えます。 またbatを実行しようとしたけど、できなかった時の原因と対&#8230;</span>					</div>
				</div>
			</div>
		</div>


<p>上のコードを記述した「file_create.bat」を作成して実行して見ます。</p>


<div class="wp-block-image is-style-desktop">
<figure class="aligncenter size-full"><img decoding="async" width="795" height="131" src="https://sugublog.org/wp-content/uploads/2023/05/bat_file_create.png" alt="batファイルでファイルを作成するスクリプトを実行した結果" class="wp-image-5527" srcset="https://sugublog.org/wp-content/uploads/2023/05/bat_file_create.png 795w, https://sugublog.org/wp-content/uploads/2023/05/bat_file_create-300x49.png 300w, https://sugublog.org/wp-content/uploads/2023/05/bat_file_create-768x127.png 768w" sizes="(max-width: 795px) 100vw, 795px" /></figure>
</div>


<p class="has-border -border02">空のファイルが２つと指定した文字が入った１つのファイル、合計３つのファイルが作成されている事が分かります。</p>



<p>このようにbatでファイルを作成すると便利です。</p>



<h2 class="wp-block-heading">batでファイル作成に関連するコマンド</h2>



<h3 class="wp-block-heading">ファイル削除する方法</h3>


<div class="swell-block-postLink">			<div class="p-blogCard -internal" data-type="type1" data-onclick="clickLink">
				<div class="p-blogCard__inner">
					<span class="p-blogCard__caption">あわせて読みたい</span>
					<div class="p-blogCard__thumb c-postThumb"><figure class="c-postThumb__figure"><img decoding="async" src="https://sugublog.org/wp-content/uploads/2021/12/結婚1209-2-300x169.jpg" alt="" class="c-postThumb__img u-obf-cover" width="320" height="180"></figure></div>					<div class="p-blogCard__body">
						<a class="p-blogCard__title" href="https://sugublog.org/bat-file-delete/">【bat】ファイルを削除する方法！エラー対処法あり</a>
						<span class="p-blogCard__excerpt">様々なスクリプトでファイルを削除する方法が違うので、batでファイルを削除する方法を教えて欲しいです。 またファイル削除する前に確認を入れたいです。 問答無用で削&#8230;</span>					</div>
				</div>
			</div>
		</div>


<h3 class="wp-block-heading">フォルダ削除する方法</h3>


<div class="swell-block-postLink">			<div class="p-blogCard -internal" data-type="type1" data-onclick="clickLink">
				<div class="p-blogCard__inner">
					<span class="p-blogCard__caption">あわせて読みたい</span>
					<div class="p-blogCard__thumb c-postThumb"><figure class="c-postThumb__figure"><img decoding="async" src="https://sugublog.org/wp-content/uploads/2021/07/PC007-8-300x182.jpg" alt="" class="c-postThumb__img u-obf-cover" width="320" height="180"></figure></div>					<div class="p-blogCard__body">
						<a class="p-blogCard__title" href="https://sugublog.org/bat-folder-rmdir/">【bat基礎】フォルダ削除する方法！エラー解消法あり</a>
						<span class="p-blogCard__excerpt">batファイルでフォルダ削除したい時に動かなくて困った事はありませんか？ サブフォルダまで削除したり、強制的にフォルダ削除したいなどの要望はありませんか？ ワイル&#8230;</span>					</div>
				</div>
			</div>
		</div>


<h3 class="wp-block-heading">ファイル名を取得するコマンドについて</h3>


<div class="swell-block-postLink">			<div class="p-blogCard -internal" data-type="type1" data-onclick="clickLink">
				<div class="p-blogCard__inner">
					<span class="p-blogCard__caption">あわせて読みたい</span>
					<div class="p-blogCard__thumb c-postThumb"><figure class="c-postThumb__figure"><img decoding="async" src="https://sugublog.org/wp-content/uploads/2021/11/Server_20211109-19-300x148.jpg" alt="" class="c-postThumb__img u-obf-cover" width="320" height="180"></figure></div>					<div class="p-blogCard__body">
						<a class="p-blogCard__title" href="https://sugublog.org/bat-filename-get/">【bat基礎】ファイル名を取得する様々な方法！簡単に取得可能です</a>
						<span class="p-blogCard__excerpt">batファイルでファイル名を取得する方法が分かりません。実行しているファイルやカレントディレクトリにあるファイル名を取得したい！ batファイルでファイル名を取得す&#8230;</span>					</div>
				</div>
			</div>
		</div>


<h3 class="wp-block-heading">ファイルの存在をチェックして処理を分ける方法</h3>


<div class="swell-block-postLink">			<div class="p-blogCard -internal" data-type="type1" data-onclick="clickLink">
				<div class="p-blogCard__inner">
					<span class="p-blogCard__caption">あわせて読みたい</span>
					<div class="p-blogCard__thumb c-postThumb"><figure class="c-postThumb__figure"><img decoding="async" src="https://sugublog.org/wp-content/uploads/2021/12/PC教室20211216-9-300x125.jpg" alt="" class="c-postThumb__img u-obf-cover" width="320" height="180"></figure></div>					<div class="p-blogCard__body">
						<a class="p-blogCard__title" href="https://sugublog.org/bat-file-exist-check/">【bat基礎】ファイル存在チェックする方法!existsを使用します！</a>
						<span class="p-blogCard__excerpt">batを使用していてファイル存在チェックしたい場合のやり方をご紹介します。existsを使用します。 もしファイルが存在したら〇〇、存在しなければ作成するといった場合&#8230;</span>					</div>
				</div>
			</div>
		</div>


<h3 class="wp-block-heading">ファイルを移動したい場合のbatの書き方</h3>


<div class="swell-block-postLink">			<div class="p-blogCard -internal" data-type="type1" data-onclick="clickLink">
				<div class="p-blogCard__inner">
					<span class="p-blogCard__caption">あわせて読みたい</span>
					<div class="p-blogCard__thumb c-postThumb"><figure class="c-postThumb__figure"><img decoding="async" src="https://sugublog.org/wp-content/uploads/2021/11/programing_shool1121-4-300x180.jpg" alt="" class="c-postThumb__img u-obf-cover" width="320" height="180"></figure></div>					<div class="p-blogCard__body">
						<a class="p-blogCard__title" href="https://sugublog.org/bat-file-move/">【bat基礎】ファイル移動するやり方！ファイル名変更なども行えます！</a>
						<span class="p-blogCard__excerpt">batファイルでファイル移動する場合のやり方を今回行います。 また移動先に同じファイル名があった時の対処法なども、現役エンジニアの筆者が一緒に伝えます。 moveコマ&#8230;</span>					</div>
				</div>
			</div>
		</div>]]></content:encoded>
					
					<wfw:commentRss>https://sugublog.org/bat-file-create/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
