2

I need it to work on Win10 and Win7 machines. If I can get this to work I'll make a batch file.

Winkey, "cmd" cd "e:\media\trainingvids" dir *.* /s /b /a -d > c:\temp\dork.txt 

So, to state the obvious but make sure I'm getting it, I'm opening a command prompt, changing to the correct directory, doing a directory listing of all files (including sub-directories (/s), no headers or footers so 'bare' format (/b), and trying to NOT display the directory (/a -d) – and then sending/piping that (>) to a file I've designated to be named and created (dork.txt) in a temporary directory (\temp) that already exists on my c:.

The problem is that it doesn't work. I'm not able to find a way to NOT include the full path along with the file names. I need a nudge with the syntax. Or maybe I've got it all wrong and it can't be done in this way.

What does my Basic batch file look like that can do this?

5
  • Use /a:-a or /a-d, with no space in between; Commented Jan 4, 2016 at 5:00
  • @aschipfl - Thanks, but I've tried those. No worky. (Note: I had to remove the space after “dir” in the OP to make the star-dot-star show up correctly.) Commented Jan 4, 2016 at 5:06
  • The SPACE after dir is required -- dir*.* results in an error, while dir *.* works fine... Commented Jan 4, 2016 at 5:08
  • 1
    Din't use "smart quotes"! - standard quotes are required. Not sure whether your OP intended to include the space between the /a and d, so I left it there. To post a code snippet, indent each line 4 spaces or select and press {} which does the same thing Commented Jan 4, 2016 at 5:14
  • I can't imagine why you would want to include sub-directories, yet not include the path in the output. Just the file name by itself doesn't tell you very much. Commented Jan 4, 2016 at 5:21

4 Answers 4

1

You will need the for /F command to accomplish this:

> "D:\temp\dork.txt" ( for /F "eol=| delims=" %%F in (' dir /B /S /A:-D "E:\media\trainingvids\*.*" ') do @( echo(%%~nxF ) ) 

You placed a SPACE between /A and -D in your dir command line, which must be removed.

Since I stated the full path to the target directory in the dir command and also to the output file, you can save this script at any location and run it from anywhere.

Sign up to request clarification or add additional context in comments.

4 Comments

I copied and pasted your code into a “test.bat” file (changed "D:" to "C:" - I also moved E: to C: for testing - so all are on C:). It runs great, but the results are: LineItem1: blank space, LineItem2: {C:\Temp>(echo(vid1.mp4 )}, LineItem3: exactly just the file name I need. So I have 3 line-items per each file instead of the one. So close. Hope that makes sense.
just a @echo off needed (as very first line).
Yes, @Stephan is right; or you insert a @ character where I did (see my edit which has the same effect...
Oh boy – THIS! I already accepted the other, but now I'm going to flip-flop, because this is perfect! What a disaster first post, sorry all, but WE DID IT!
1
for /f "delims=" %%a in ('dir /s/b/a-d') do echo %%~nxa 

should accomplish that task.

2 Comments

That would be the case if you are running from the prompt. You asked for a batch file, so you got the batch format (and obviously, the cd wasn't included). You could also add "e:\media\trainingvids" as an argument into the dir command to see the list from anywhere (ie regardless of current directory). To run from the prompt, reduce each %% to % Enclose the entire line in parentheses and add your redirection to create a file (for...~nxa)>filename
Sorry. I'm also trying to run that in a batch file, and gimping the syntax to match, but to no avail – because I am dumb like a drunk chicken pecking the keyboard.
1

If you can tolerate double quoted names this batch file works well.

set myPath=c:\temp set myMask=*.pdf set myLog=c:\temp\myLogFile.log FORFILES /P %myPath% /S /M %myMask% /C "CMD /C ECHO @file >> %myLog%" 

Alter the values to meet your needs.

8 Comments

Thank you, but none of the file names in the sub-directories are captured. (/s) is needed.
I added it to the above example.
Except for adding it doesn't work (full file path included in result file), and no matter what order I try the switches, and how hard I bang my head against the wall. Apparently three switches doint work?? I copied and pasted your text too. No worky.
Yes, I knew that too. Sorry. You specified Batch and i'm afraid that the way i'd do this is with VBscript which is outside your specs.
Yep. I'm just running a test.bat text file created in Notepad. (Also testing the syntax at a DOS prompt.)
|
1

You're almost there with:

dir /s /w /a-d | find "." 

The only drawback is that you get the file names in columns, and possibly a Volume line which you can remove with another find filter.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.