テキスト ファイルの最初の行を取得し、末尾のバックスラッシュがある場合はそれを削除しようとする短いバッチ スクリプトを作成しています。これは、入力ファイルの残りの行に対して繰り返されます。ただし、スクリプトを実行すると、行からバックスラッシュが削除されません。これは簡単な修正だと思いますが、いくつかのトラブルシューティング方法を試しましたがうまくいきませんでした。参考までに以下にコードを載せておきます。ありがとう!
@echo on
setLocal EnableDelayedExpansion
::set firstline to firstline of test.txt
set /p firstline=<test.txt
::Remove trailing slash if present
IF !firstline:~-1!==\ SET firstline=!firstline:~0,-1!
::Output firstline (without \ to new txt file)
echo !firstline!>test2.txt
endlocal
test.txt ファイル:
C:\Desktop\example\path\
C:\Desktop\example\path\2\
C:\Desktop\example\path\test\