Batch job to check filenames and archiveBatch script with for loop and pipeHow can I pass arguments to a batch file?Split long commands in multiple lines through Windows batch fileWindows batch files: .bat vs .cmd?How to sleep for 5 seconds in a batch file/cmd?How to “comment-out” (add comment) in a batch/cmd?The filename directory name or volume label syntax is incorrectBatch file that moves files when string is not in filename or when a file has finish writingUNC Paths Not Supported in called batch fileHow to rename or create a zip file with the name of its content using a batch fileChecking for naming convention in file?

Lay out the Carpet

How does the UK government determine the size of a mandate?

What is the opposite of 'gravitas'?

Is expanding the research of a group into machine learning as a PhD student risky?

What is the best translation for "slot" in the context of multiplayer video games?

Avoiding estate tax by giving multiple gifts

Why didn't Theresa May consult with Parliament before negotiating a deal with the EU?

What happens if you roll doubles 3 times then land on "Go to jail?"

Escape a backup date in a file name

Term for the "extreme-extension" version of a straw man fallacy?

How do scammers retract money, while you can’t?

Where does the Z80 processor start executing from?

Sequence of Tenses: Translating the subjunctive

Is the destination of a commercial flight important for the pilot?

How does Loki do this?

Is there a problem with hiding "forgot password" until it's needed?

How did Arya survive the stabbing?

How does buying out courses with grant money work?

Did Dumbledore lie to Harry about how long he had James Potter's invisibility cloak when he was examining it? If so, why?

Different result between scanning in Epson's "color negative film" mode and scanning in positive -> invert curve in post?

India just shot down a satellite from the ground. At what altitude range is the resulting debris field?

What is paid subscription needed for in Mortal Kombat 11?

How to check is there any negative term in a large list?

What does 算不上 mean in 算不上太美好的日子?



Batch job to check filenames and archive


Batch script with for loop and pipeHow can I pass arguments to a batch file?Split long commands in multiple lines through Windows batch fileWindows batch files: .bat vs .cmd?How to sleep for 5 seconds in a batch file/cmd?How to “comment-out” (add comment) in a batch/cmd?The filename directory name or volume label syntax is incorrectBatch file that moves files when string is not in filename or when a file has finish writingUNC Paths Not Supported in called batch fileHow to rename or create a zip file with the name of its content using a batch fileChecking for naming convention in file?













0















I have a directory where users are saving their excel files that should adhere to a specific naming convention:



XX-TestFile.xlsx


where XX is a variable digit and -TestFile.xlsx should always be the same and not change. I'd like to be able to check through a batch job if files in the directory adhere to this naming convention.



If filename is misspelled, i.e. XX-TetsFiel.xlsx, XX is not a digit like 02 or even XX-testfile.xlsx (all lowercase), then files should move to an Error directory.



I am using below to move the files to achieve this. I am testing with 11-testFiel.xlsx but when I execute the .bat nothing happens - I get no errors and the file remains where it was before:



@echo off

for /f "delims=" %%a in ('dir /b *.xlsx | findstr /v "[0-9][0-9]-TestFile.xlsx"') do move "%%a" "C:TempArchiveError"


Many thanks in advance for your help!










share|improve this question



















  • 4





    The pipe symbol | has to be escaped with a caret ^| inside a for /f command. If you'd executed the batch in an open cmd window you would see the error message.

    – LotPings
    Mar 21 at 16:23












  • @LotPings: Thanks, that worked!

    – Aligator3000
    Mar 21 at 16:31






  • 1





    You need to escape | with the batch file escape character, the caret (^), so it will become ^|. This happens because | is executed in higher prio than the for loop.

    – double-beep
    Mar 21 at 16:34











  • @double-beep.. but LotPings already said that... why not just upvote his comment instead of repeating it?

    – Gerhard Barnard
    Mar 21 at 17:18












  • @GerhardBarnard sorry, this is not a place to discuss that, but as you can see, I have added some explanations.

    – double-beep
    Mar 21 at 18:28















0















I have a directory where users are saving their excel files that should adhere to a specific naming convention:



XX-TestFile.xlsx


where XX is a variable digit and -TestFile.xlsx should always be the same and not change. I'd like to be able to check through a batch job if files in the directory adhere to this naming convention.



If filename is misspelled, i.e. XX-TetsFiel.xlsx, XX is not a digit like 02 or even XX-testfile.xlsx (all lowercase), then files should move to an Error directory.



I am using below to move the files to achieve this. I am testing with 11-testFiel.xlsx but when I execute the .bat nothing happens - I get no errors and the file remains where it was before:



@echo off

for /f "delims=" %%a in ('dir /b *.xlsx | findstr /v "[0-9][0-9]-TestFile.xlsx"') do move "%%a" "C:TempArchiveError"


Many thanks in advance for your help!










share|improve this question



















  • 4





    The pipe symbol | has to be escaped with a caret ^| inside a for /f command. If you'd executed the batch in an open cmd window you would see the error message.

    – LotPings
    Mar 21 at 16:23












  • @LotPings: Thanks, that worked!

    – Aligator3000
    Mar 21 at 16:31






  • 1





    You need to escape | with the batch file escape character, the caret (^), so it will become ^|. This happens because | is executed in higher prio than the for loop.

    – double-beep
    Mar 21 at 16:34











  • @double-beep.. but LotPings already said that... why not just upvote his comment instead of repeating it?

    – Gerhard Barnard
    Mar 21 at 17:18












  • @GerhardBarnard sorry, this is not a place to discuss that, but as you can see, I have added some explanations.

    – double-beep
    Mar 21 at 18:28













0












0








0








I have a directory where users are saving their excel files that should adhere to a specific naming convention:



XX-TestFile.xlsx


where XX is a variable digit and -TestFile.xlsx should always be the same and not change. I'd like to be able to check through a batch job if files in the directory adhere to this naming convention.



If filename is misspelled, i.e. XX-TetsFiel.xlsx, XX is not a digit like 02 or even XX-testfile.xlsx (all lowercase), then files should move to an Error directory.



I am using below to move the files to achieve this. I am testing with 11-testFiel.xlsx but when I execute the .bat nothing happens - I get no errors and the file remains where it was before:



@echo off

for /f "delims=" %%a in ('dir /b *.xlsx | findstr /v "[0-9][0-9]-TestFile.xlsx"') do move "%%a" "C:TempArchiveError"


Many thanks in advance for your help!










share|improve this question
















I have a directory where users are saving their excel files that should adhere to a specific naming convention:



XX-TestFile.xlsx


where XX is a variable digit and -TestFile.xlsx should always be the same and not change. I'd like to be able to check through a batch job if files in the directory adhere to this naming convention.



If filename is misspelled, i.e. XX-TetsFiel.xlsx, XX is not a digit like 02 or even XX-testfile.xlsx (all lowercase), then files should move to an Error directory.



I am using below to move the files to achieve this. I am testing with 11-testFiel.xlsx but when I execute the .bat nothing happens - I get no errors and the file remains where it was before:



@echo off

for /f "delims=" %%a in ('dir /b *.xlsx | findstr /v "[0-9][0-9]-TestFile.xlsx"') do move "%%a" "C:TempArchiveError"


Many thanks in advance for your help!







batch-file for-loop io-redirection






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 21 at 19:17









aschipfl

19.2k92958




19.2k92958










asked Mar 21 at 15:56









Aligator3000Aligator3000

109215




109215







  • 4





    The pipe symbol | has to be escaped with a caret ^| inside a for /f command. If you'd executed the batch in an open cmd window you would see the error message.

    – LotPings
    Mar 21 at 16:23












  • @LotPings: Thanks, that worked!

    – Aligator3000
    Mar 21 at 16:31






  • 1





    You need to escape | with the batch file escape character, the caret (^), so it will become ^|. This happens because | is executed in higher prio than the for loop.

    – double-beep
    Mar 21 at 16:34











  • @double-beep.. but LotPings already said that... why not just upvote his comment instead of repeating it?

    – Gerhard Barnard
    Mar 21 at 17:18












  • @GerhardBarnard sorry, this is not a place to discuss that, but as you can see, I have added some explanations.

    – double-beep
    Mar 21 at 18:28












  • 4





    The pipe symbol | has to be escaped with a caret ^| inside a for /f command. If you'd executed the batch in an open cmd window you would see the error message.

    – LotPings
    Mar 21 at 16:23












  • @LotPings: Thanks, that worked!

    – Aligator3000
    Mar 21 at 16:31






  • 1





    You need to escape | with the batch file escape character, the caret (^), so it will become ^|. This happens because | is executed in higher prio than the for loop.

    – double-beep
    Mar 21 at 16:34











  • @double-beep.. but LotPings already said that... why not just upvote his comment instead of repeating it?

    – Gerhard Barnard
    Mar 21 at 17:18












  • @GerhardBarnard sorry, this is not a place to discuss that, but as you can see, I have added some explanations.

    – double-beep
    Mar 21 at 18:28







4




4





The pipe symbol | has to be escaped with a caret ^| inside a for /f command. If you'd executed the batch in an open cmd window you would see the error message.

– LotPings
Mar 21 at 16:23






The pipe symbol | has to be escaped with a caret ^| inside a for /f command. If you'd executed the batch in an open cmd window you would see the error message.

– LotPings
Mar 21 at 16:23














@LotPings: Thanks, that worked!

– Aligator3000
Mar 21 at 16:31





@LotPings: Thanks, that worked!

– Aligator3000
Mar 21 at 16:31




1




1





You need to escape | with the batch file escape character, the caret (^), so it will become ^|. This happens because | is executed in higher prio than the for loop.

– double-beep
Mar 21 at 16:34





You need to escape | with the batch file escape character, the caret (^), so it will become ^|. This happens because | is executed in higher prio than the for loop.

– double-beep
Mar 21 at 16:34













@double-beep.. but LotPings already said that... why not just upvote his comment instead of repeating it?

– Gerhard Barnard
Mar 21 at 17:18






@double-beep.. but LotPings already said that... why not just upvote his comment instead of repeating it?

– Gerhard Barnard
Mar 21 at 17:18














@GerhardBarnard sorry, this is not a place to discuss that, but as you can see, I have added some explanations.

– double-beep
Mar 21 at 18:28





@GerhardBarnard sorry, this is not a place to discuss that, but as you can see, I have added some explanations.

– double-beep
Mar 21 at 18:28












0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55284467%2fbatch-job-to-check-filenames-and-archive%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55284467%2fbatch-job-to-check-filenames-and-archive%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript