Goodday,<\/p>\n
I have a folder with a lot of .csv-files. A part of the name of the csv-file contains the date it is made.
\nI want to copy some of these csv-files into 1 text-file.
\nMy code below does its job the files with the date YYYYMMDD = 20210417 and the number ‘3’ at a certain place in the filename.<\/p>\n
So it works, but I have to manually change the date to ‘Today’ everytime I use this code.
\nCan someone show me how I automatically use the date of Today (YYYYMMDD)?
\nAnd can that DateOfToday also be used as the ‘filename.txt’ (YYYYMMDD.txt)?<\/p>\n
I am very new to PowerShell.<\/p>\n
Kind regards<\/p>\n
cat *20210417*3????.csv | ForEach-object { if(\"$_\" -notlike \"bonnr*\") { $_ +\";3\" >> C:\\Foldername\\filename.txt}}\n<\/code><\/pre>","upvoteCount":3,"answerCount":13,"datePublished":"2021-04-17T19:43:04.000Z","author":{"@type":"Person","name":"plinka","url":"https://community.spiceworks.com/u/plinka"},"acceptedAnswer":{"@type":"Answer","text":"idk something like so?<\/p>\n
$today = get-date -f yyyyMMdd\n\n$fileContent = \nforeach ($file in (get-childitem *$today*3*.csv)) {\n $pcnum = ($file.name)[-9]\n Get-content $file |\n select-object -skip 1 |\n ForEach-Object{\n $_ + \";$pcnum\"\n }\n}\n\n$filecontent | \nout-file \"FileContent_$today.txt\" -force\n<\/code><\/pre>","upvoteCount":1,"datePublished":"2021-04-17T20:56:00.000Z","url":"https://community.spiceworks.com/t/using-todaydate-as-string/797216/10","author":{"@type":"Person","name":"Neally","url":"https://community.spiceworks.com/u/Neally"}},"suggestedAnswer":[{"@type":"Answer","text":"Goodday,<\/p>\n
I have a folder with a lot of .csv-files. A part of the name of the csv-file contains the date it is made.
\nI want to copy some of these csv-files into 1 text-file.
\nMy code below does its job the files with the date YYYYMMDD = 20210417 and the number ‘3’ at a certain place in the filename.<\/p>\n
So it works, but I have to manually change the date to ‘Today’ everytime I use this code.
\nCan someone show me how I automatically use the date of Today (YYYYMMDD)?
\nAnd can that DateOfToday also be used as the ‘filename.txt’ (YYYYMMDD.txt)?<\/p>\n
I am very new to PowerShell.<\/p>\n
Kind regards<\/p>\n
cat *20210417*3????.csv | ForEach-object { if(\"$_\" -notlike \"bonnr*\") { $_ +\";3\" >> C:\\Foldername\\filename.txt}}\n<\/code><\/pre>","upvoteCount":3,"datePublished":"2021-04-17T19:43:04.000Z","url":"https://community.spiceworks.com/t/using-todaydate-as-string/797216/1","author":{"@type":"Person","name":"plinka","url":"https://community.spiceworks.com/u/plinka"}},{"@type":"Answer","text":"Welcome<\/p>\n
If you post code, please use the ‘Insert Code’ button. Please and thank you!<\/p>\n